I am trying 2 load details about cars from a.txt file
and then display the total stock value off all cars.
this is my first class attemt with out loading in a file.
3nd Class
This is the format of my text file
V40GOR
Vauxhall
Omega 2.0 CD
1998
1000
76000
L17LLL
Rover
MGF 1.8
1998
4000
45000
CW04ABC
car manufacturer 1
car model 1
2004
40000
10000
CW04XYZ
car manufacturer 1
car model 2
2004
10000
5000
****
Thanx in advance for any help.
and then display the total stock value off all cars.
Code:
public class Car
{
// attributes
private String manufacturer;
private String model;
private String regNo;
private int year;
private int price;
// constructor
public Car(String newManufacturer, String model, String regNo, int year, int price)
{
this.manufacturer = newManufacturer;
this.model = model;
this.regNo = regNo;
this.year = year;
this.price = price;
}
// another constructor
public Car()
{
}
// mutator methods
public void setManufacturer(String manufacturer)
{
this.manufacturer = manufacturer;
}
public void setModel(String model)
{
this.model = model;
}
public void setRegNo(String regNo)
{
this.regNo = regNo;
}
public void setYear(int year)
{
this.year = year;
}
public void setPrice(int price)
{
this.price = price;
}
public String getManufacturer()
{
return this.manufacturer;
}
// accessor methods
public String getModel()
{
return this.model;
}
public String getRegNo()
{
return this.regNo;
}
public int getYear()
{
return this.year;
}
public int getPrice()
{
return this.price;
}
public String toString()
{
return "Car details \nManufacturer :" + manufacturer +
"\nModel :" + model +
"\nRegistration number :" + regNo +
"\nYear :" + year +
"\nPrice :£" + price;
}
public static void main(String[] args)
{
Car car = new Car("Vauxhall", "Omega 2.0 GLS", "M21VUR", 1995, 1000);
Car car1 = new Car("rustbucket","corsa 1.6","T32brt", 1998, 2350);
System.out.println(car+car1.toString());
}// end of main method
}// end of class Car
Code:
import java.io.*;
public class Motors
{
private Garage theGarage = null;
public static void main ( String [] args ) throws IOException
{
theGarage = new Garage();
}//main
}//Motors
3nd Class
Code:
import java.io.*;
public class Garage
{
private static final int MAX_CARS = 10;
private Car [] carDetails = new Car[MAX_CARS];
private int carCount = 0;
private static final String textFilesPath = "C:\\Documents and Settings\\owz\\Desktop\\RESIT DO NOW\\car details.txt";
public Garage() throws IOException
{
loadCarDetails();
}
public void loadCarDetails() throws IOException
{
BufferedReader inputCarFile;
String aManufacturer;
String aModel;
String aRegNo;
int aYear;
int aPrice;
inputCarFile = Text.open ( textFilesPath );
for ( int i = 0; i < MAX_CARS; i++ )
{
carDetails[ i ] = new Car( );
}//end for
}// end of loadCarDetails method
public void saveCarDetails() throws IOException
{
PrintWriter carFileOut;
carFileOut = Text.create(textFilesPath + "saved account details.txt");
carFileOut.println( "****" );
carFileOut.close();
}// end of saveCarDetails method
public void addCar( String aManufacturer,
String aModel,
String aRegNo,
int aYear,
int aPrice )
{
}//addCar
public boolean garageFull(String aRegNo)
{
boolean garageFull = false;
if (aRegNo = 11)
{
garageFull = true;
}
return garageFull ; // something true or false
}//garageFull
public void listCarDetails()
{
}// end of listCarDetails method
public int totalStockValue()
{
int stockValue = 0;
return stockValue;
}// end of totalStockValue method
public int getCarCount()
{
return this.carCount ;//something
}//getCarCount
public Car getCarDetail( int entry )
{
return ;//something
}//getCarDetail
//Other methods required
public static void main(String[] args) throws IOException
{
Garage garage = new Garage();
garage.loadCarDetails();
garage.listCarDetails();
System.out.println("The total value of car stock is £" + garage.totalStockValue());
Text.showMessage("That's all folks");
System.exit(0);
}// end of main method
}// end of class Garage
This is the format of my text file
V40GOR
Vauxhall
Omega 2.0 CD
1998
1000
76000
L17LLL
Rover
MGF 1.8
1998
4000
45000
CW04ABC
car manufacturer 1
car model 1
2004
40000
10000
CW04XYZ
car manufacturer 1
car model 2
2004
10000
5000
****
Thanx in advance for any help.
Comment