is there anyone that can help me with java program I spent hour troubleshooting? I have no problem reading the file into a string array but I don't seem to know how to use switch or maybe if statement to store each line in an Array of Objects.
Write an application with a main that reads a file (from the command line) and fills an array of type vehicle[] with new vehicle (params), new car (params), new american car (params) new foreign car(params) , new truck (params), new bicycle (params), etc. depending on the first line that identifies each record. sample of data:
vehicle
eRob
Rob's house
(987) 654-3210
[email protected]truck
aDougy
Doug's house
(123) 456-7890
[email protected]
30
61234.56
8/10/2003bicycle
fTom
Tom's house
(246) 810-1214
[email protected]
7
If you see whats wrong with my code, please point at it:
public static void main( String[] args) throws Exception
{
int traceOfArray = 100;
Vehicle[] vehicle = new Vehicle[traceOfArray];
File file = null;
file = new File(args[0]);
FileReader Fr = new FileReader(file); //read file.
BufferedReader Br = new BufferedReader(Fr);
String read = Br.readLine();
try
{
while (read != null)
{
char x = read.charAt(0);
if(x=='v')
vehicle[0] = new Vehicle(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
else if(x=='c')
vehicle[1] = new Car(Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine(), Br.readLine());
...