Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Car Dealership program  RSS feed

 
niraj pateI
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Coderanch I'm doing an assignment to make a Car Dealership code. These are the instructions:
For this assignment the following classes are required:


Car implements Comparable Cloneable // Do this first; it is easy. These are the minimum required.

Has private String fields for model, color, int year, int vin number and double price.
Has a default constructor (a forklist or go-cart) and has a 5 parameter constructor.
Has a toString() method which returns the model and year for example.
Has a compareTo() method based on model name.
Has a clone method.

CarLot // This is similar to the StacksAndQueues from last assignment.

Must have at least two for loops and two iterators.
Has static methods taking a LinkedList input to:
1 - display all the cars in alphabetical order with headings, one line per car. (Collections.sort(x))
2 - display the car info given a vin number
3 - list the first two cars of the same model (use compareTo)
4 - update inventory (add, delete and modify a car). Implement the code for one and display only a message for the other two.
5 - display the total value of cars in the lot.
6 - shallow clone the list. (documentation will describe it)
7 - deep clone the list. (documentation will describe it)
Note: these methods will use only the linked list data structures.

UseCarLot // The test cases!

All methods in the CarLot class to be verified with output.
You can hard code a few cars and add to a linked list. Pass this list to the CarLot class when ready.
You may want to add additional setters and getters to enable adequate testing of the cars in CarLot.
A for loop to allow additional inputs for testing can be used, and will have a termination mechanism.
Sufficient valid data testing and sufficient invalid data testing will be done to ensure correct operation. This will be documented as usual.
The clone tests will be create the clone ;test sameness; modify data(modify one car?, add one car?); test for cloneness

Menu // You decide how to implement the menu concept to do something like this.

Prompts the user with a choice of actions. The actions are the seven methods of CarLot plus exit.
Returns the choice (char?, int?) back to main for execution.
Suggest using a Singleton class -> public static final
Appropriate action forwarded to CarLot object for execution.



this is what I have so far

Car.java


What would I do for my Car.java?
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would want to see more effort from you to do this yourself. Does Car implement Comparable and Clonable? Is there any way to get to the private fields?
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Car class indeed has set up the required methods and attributes. Good start

But the class declaration is missing the Comparable and Cloneable interface


Now ask yourself: How will the variables get their values? (Hint getters and setters or this.instanceVar = paramVar)

For the toString() method, it has no argument. It is a "string representation" of the object. If this method not there, when you do System.out.println(car); the output will look like Car@1234ABCD which makes no sense. You want to display "Car is black Cardiac manufactured in 1945 with vin number 1234 cost $40000.00"
Also add the @Override annotation to the toString method to override the Object's toString() method


For the compare method (from Comparable interface), the signature is wrong, the argument should be Car not String. Use model to compare means using the model variable to sort Car objects ascending or descending order. 3 possible return values 0 means equal, 1 means greater than and -1 means less than. Since you need to compare a string (model), you can actually use the String class' compareTo() method



Not too familiar with clone. I shall let you figure that out. May want to check which class implements the Cloneable interface and check their source code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!