// Program Name:
Driver.java
// Course:
CSE 1302J
// Student Name:
Bradley Shedd
// Assignment Number:
Project#3
// Due Date:
10/20/2010
// Purpose:
This program calls the Car.java and SoldCar.java
//
compares the two for similarities and prints out
//
a car record.
import
java.io.*;
import
java.util.StringTokenizer;
public
class Driver
{
public
static
void
main(String[] args)
throws
IOException
{
StringTokenizer tokenizer;
String line, code, file="car.txt";
double
dCost, price;
int
id, day, year, mYear;
String mModel, month, customer;
Date buyDate, soldDate;
Car[] items =
new
Car[13];
FileReader fr =
new
FileReader(file);
BufferedReader inFile =
new
BufferedReader (fr);
int
i=0;
line = inFile.readLine();
tokenizer =
new
StringTokenizer (line,
" ");
code= tokenizer.nextToken();
while(code.charAt(0)
!=
'X')
{
System.out.println();
System.out.println(line);
if(code.equals("C")
|| code.equals("c"))
{
dCost = Double.parseDouble (tokenizer.nextToken());
id=Integer.parseInt(tokenizer.nextToken());
month=tokenizer.nextToken();
day=Integer.parseInt(tokenizer.nextToken());
year=Integer.parseInt(tokenizer.nextToken());
mYear=Integer.parseInt(tokenizer.nextToken());
mModel=tokenizer.nextToken();
buyDate=new
Date(day, month, year);
boolean
idFound=false;
int
j = 0;
for(j=0;
j < i && !idFound; j++)
if
(items[j].getID()==id)
idFound =
true;
if
(idFound)
System.out.println("----------------------------"
+
"Error ID was found!" +
"----------------------------");
else
{
items[i]=new
Car(dCost, id, buyDate, mYear, mModel);
boolean
duplicateCar=false;
for(int
k=0; k<i; k++)
if
(items[i].equals(items[k]))
{
System.out.println(items[k].getID());
duplicateCar=true;
}
if
(!duplicateCar)
System.out.println("---------------"
+
"No similar cars found." +
"---------------");
i++;
}
}
else
if (code.equals("S1")
|| code.equals("s1"))
{
id=Integer.parseInt(tokenizer.nextToken());
price=Double.parseDouble(tokenizer.nextToken());
customer=tokenizer.nextToken();
month=tokenizer.nextToken();
day=Integer.parseInt(tokenizer.nextToken());
year=Integer.parseInt(tokenizer.nextToken());
soldDate=new
Date(day, month, year);
for(int
j=0; j < i; j++)
if
(items[j].getID()==id)
{
Car tempCar=items[j];
items[j]=new
SoldCar(tempCar, price, customer, soldDate);
}
}
else
if(code.equals("S2")
|| code.equals("s2"))
{
dCost=Double.parseDouble(tokenizer.nextToken());
id=Integer.parseInt(tokenizer.nextToken());
month=tokenizer.nextToken();
day=Integer.parseInt(tokenizer.nextToken());
year=Integer.parseInt(tokenizer.nextToken());
mYear=Integer.parseInt(tokenizer.nextToken());
mModel=tokenizer.nextToken();
buyDate=new
Date(day, month, year);
price=Double.parseDouble(tokenizer.nextToken());
customer=(tokenizer.nextToken());
month=tokenizer.nextToken();
day = Integer.parseInt (tokenizer.nextToken());
year=Integer.parseInt(tokenizer.nextToken());
soldDate=new
Date(day, month, year);
boolean
idFound=false;
for(int
j=0; j < i && !idFound; j++)
if
(items[j].getID()==id)
idFound =
true;
if
(idFound)
System.out.println("----------------------------"
+
"Error ID was found!" +
"----------------------------");
else
{
items[i]=new
SoldCar(dCost, id, buyDate,
price, customer, soldDate, mModel, mYear);
boolean
duplicateCar=false;
for(int
k=0; k<i; k++)
if
(items[i].equals(items[k]))
{
System.out.println(items[k].getID());
duplicateCar=true;
}
if
(!duplicateCar)
System.out.println("------------------------------"
+
"No similar cars found." +
"-------------------------------");
i++;
}
}
line = inFile.readLine();
tokenizer =
new
StringTokenizer (line,
" ");
code= tokenizer.nextToken();
}
System.out.println("\r*************************************"
+
"**********************************************");
System.out.println("\nCar
Records: ");
for
(int j=0; j<i; j++)
System.out.println("--------------------------------"
+
"\nCar " + (j+1)+
"\n"
+ items[j]);
System.out.println("\r\rCoded
By: Bradley J. Shedd");
}
}