Rahul Bajaj

Ranch Hand
+ Follow
since Sep 21, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Rahul Bajaj

How can I achieve that? please explain
18 years ago
Here is the code I made


import java.io.*;
import java.util.*;


class Demo2
{
public static void main(String args[])
{
for(int i=0; i < args.length; i++)
System.out.println( args[i] );



// args.length is equivalent to argc in C
if (args.length == 3)
{

try
{
// Open the file that is the first command line parameter

FileInputStream fstream = new
FileInputStream(args[0]);

// Convert our input stream to a BufferedReader


BufferedReader in = new BufferedReader(new InputStreamReader(fstream));
String inputLine;

// Continue to read lines while there are still some left to read

while ((inputLine = in.readLine()) != null)
{
Vector v = new Vector(); //create vector

String[] words = inputLine.split(","); // comma.
for (int j=0;j< words.length;j++)
{
try
{
v.add(new String(words[j]));
} catch (NumberFormatException ignored)
try
{
v.add(words[j]);
}catch (NumberFormatException ignored)

}


}
}

in.close();
}
catch (Exception e)
{
System.err.println("File input error");
}
}
else
System.out.println("Invalid parameters");
}


}
18 years ago
Hello
I am trying to write this programme, any help will be good, I have solved upto some extent I will post the code. Now I am not sure how to use Multimap so that I can have one key associated with all values in a row.Please help.

"Customer Name","Trade Date","Symbol","Quantity","Price","Commissions"
"Rick","1/20/2005","JPP","5","85.56","2.5"
"Rick","2/20/2005","JPP","-9","100.58","2.5"
"Rick","8/1/2005","POL","7","2.3","1.3"
"Rick","8/1/2005","POL","2","2.2","1.3"

and it shoud produce the o/p

"Customer","Symbol","Quantity","Date Bought","Date Sold","Purchase Price","Selling Price","Gain/Loss","Status"
"Rick","JPP","4","","2/20/2005","","399.82","Unknown","B"
"Rick","JPP","5","1/20/2005","2/20/2005","430.3","500.4","70.1","M"
"Rick","POL","9","8/1/2005","","23.1","","Unknown","H"

Which is like selling buying of trades.



The rules of transformations are:



1. Customers can only sell stocks that they already own. (So if a person did not buy a stock in 2005 but then sold it in 2005 we assume that he bought it before 1/1/2005.)



2. Transactions done on the same date for the same stock should be combined together for the output, with commissions and sales or purchase prices added.



3. There are three resulting states:

M=stock bought in the current year and sold in the current year,

B=stock bought before the current year and sold in the current year,

H=stock bought in the current year and held thru the end of the year.



4. Sales price = quantity x price � commission

5. Purchase price = quantity x price + commission

6. Gain/Loss = Sales Price � Purchase Price
18 years ago
Looks little difficult to me, any hint will be good.
18 years ago
My i/p file is

"Customer Name","Trade Date","Symbol","Quantity","Price","Commissions"
"Rick","1/20/2005","JPP","5","85.56","2.5"
"Rick","2/20/2005","JPP","-9","100.58","2.5"
"Rick","8/1/2005","POL","7","2.3","1.3"
"Rick","8/1/2005","POL","2","2.2","1.3"

and it shoud produce the o/p

"Customer","Symbol","Quantity","Date Bought","Date Sold","Purchase Price","Selling Price","Gain/Loss","Status"
"Rick","JPP","4","","2/20/2005","","399.82","Unknown","B"
"Rick","JPP","5","1/20/2005","2/20/2005","430.3","500.4","70.1","M"
"Rick","POL","9","8/1/2005","","23.1","","Unknown","H"

Which is like selling buying of trades.



The rules of transformations are:



1. Customers can only sell stocks that they already own. (So if a person did not buy a stock in 2005 but then sold it in 2005 we assume that he bought it before 1/1/2005.)



2. Transactions done on the same date for the same stock should be combined together for the output, with commissions and sales or purchase prices added.



3. There are three resulting states:

M=stock bought in the current year and sold in the current year,

B=stock bought before the current year and sold in the current year,

H=stock bought in the current year and held thru the end of the year.



4. Sales price = quantity x price � commission

5. Purchase price = quantity x price + commission

6. Gain/Loss = Sales Price � Purchase Price
18 years ago
Somebody plz help...
18 years ago
Hello,
I am working on a program where I have a input file seperated by comma. I want to pull out the different columns and based on there values need to do some calculations and again generate output file with the result. I have to give Input file location, Customer name and output file location from command line and rows with the customer name given will be selected and operations will be performed only on those rows.

How can I achieve that? means how to extract columns info?
18 years ago
Thanks,It worked. I am able to execute now.
18 years ago
and for javac -version o/p is

javac 1.5.0_02

which means I have 1.3 and 1.5, what can I do to resolve?
18 years ago
Output of java -version is


I:\>java -version
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
18 years ago
I have JavaSDK 1.4 installed at my computer. I am trying to compile and execute java prog. I am able to compile as I have set the path but during execution I am getting following error.Do I need to set classpath?
If yes how?

\>java FileInputDemo test.txt
Exception in thread "main" java.lang.UnsupportedClassVersionError: FileInputDemo
(Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
18 years ago
Also which function will get called?


int abs(int n);
long abs(long n);
double abs(double n);
float abs(float n);
int main()
{
cout << abs(-10L);
return 0;
}


according to me it should be long abs(long) but its incorrect...according to answers of mock exam.
char a [] = "ABCD\r\n" ; How many elements are there in array?

Answer is 7...but according to me it should be 6 b'coz /r is carriage return and /n is new line, does arrays also have one more /n as like Strings?
Thanks, Uzma. It has definately helped me.
No, It just reads "Your Name has fulfilled all the requirements as Java Programmer" But good percentage means you can have more confidence.