# Help with used car program (java)



## Twista (Mar 4, 2004)

I need to create two classes, one called car (this is the actual car object) and one called carlist (this is an array of cars which are for sale). I of course also need to create an additional driver class for the program (this will contain the main method which will create objects and call their methods, and I need to use the keyboard class to get input from the user).

The program should be capable of providing the following user experience:

ACME Used Car Dealers

1. Purchase car
2. Display cars for sale
3. Sell car

Enter option: 1

PURCHASE CAR
MAKE: Ford
Model: Escort
Year: 2001
Miles: 3400
Color: White
Purchase price: 1500
Sale price: 2495

1. Purchase car
2. Display cars for sale
3. Sell car

Enter option: 2

CARS FOR SALE

No Make Model Year Miles Color Price
1 Ford Escort 2001 3400 White 2495
2 Saab 93 2000 56000 Black 4999

1. Purchase car
2. Display cars for sale
3. Sell car

Enter option: 3

SELL A CAR
Which car: 1
What price: 2395
Sold a White Ford Escort 2001
You just made us $895 profit


BTW, each car object should store (at a minimum) the following information:

-make
-model
-year
-miles
-color
-purchase price
-for sale price
-sold flag

The carlist object will be an array of cars and a pointer to the next free location in the array for the next car to go in

I would appreciate any sort of help


----------



## MustBNuts (Aug 21, 2003)

what sort of code do you have so far? when is the assignment due?


----------



## Twista (Mar 4, 2004)

Thanks for the response

Here is the code I have so far for the car class

import java.text.NumberFormat;
public class Car
{
// Give types for all the variables
private String make;
private String model;
private int year;
private int miles;
private String color;
private int price

// Constructor with parameters
// Create a new car with the given attributes
public Car(String make,String model,int year,int miles,String color,int price)
{
this.make = make;
this.model = model;
this.year = year;
this.miles = miles;
this.color = color;
this.price = price; 
}

// GETTERS!!!!
public String getMake()
{
return make;
}

public String getModel()
{
return model;
}

public int getYear()
{
return year;
}

public int getMiles()
{
return miles;
}

public String getColor()
{
return color;
}

public int getPrice()
{
return price;
}

public static void main (String[] args)
{
Car car1 = new Car("Ford","Escort",2001,34000,"White",2495);
Car car2 = new Car("Saab","93",2000,56000,"Black",4999);
System.out.println("car1.getMake()+" "+car1.getModel()+" "car1.getYear()+" "+car1.getMiles()+" "+car1.getColor()+" "+car1.getPrice());
System.out.println("car2.getMake()+" "+car2.getModel()+" "car2.getYear()+" "+car2.getMiles()+" "+car2.getColor()+" "+car2.getPrice());

}

}

BTW, the assignment is due tuesday


----------



## MustBNuts (Aug 21, 2003)

Okay, I figured it was homework. If you do a search on this forum with keyword homework, you will find that we don't do it here.... 

If you are having specific problems, please post your question. A post that says "this is what I need" implies you are waiting for someone to write the code for you. It won't happen here...sorry!

MBN


----------



## Twista (Mar 4, 2004)

okay, I never expected anybody to do this for me. I just need assistance.

Is this right?

CarList [] carlist = new CarList[2]; carlist [0] = new CarList(); carlist [1] = new CarList(); carlist [0].make = "Ford"; carlist [0].model = "Escort"; carlist [0].year = 2001; carlist [0].miles = 3400; carlist [0].color = "White"; carlist [0].price = 2495; carlist [1].make = "Saab"; carlist [1].model = "93"; carlist [1].year = 2000; carlist [1].miles = 56000; carlist [1].color = "Black"; carlist [1].price = 4999;


----------

