Project_05 - COMP 1210 Project 5: Used Car List Page 1 of 4...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COMP 1210 Project 5: Used Car List Page 1 of 4 Due: Monday, February 27, 2012 by 11:59 PM Deliverables The following project files must be submitted to the “graded” assignment in Web-CAT by the due date and time specified above (see the Lab Guidelines for information on submitting project files). You should plan to start on the project not later than Wednesday in lab, and you should make sure that your files are successfully submitted to the “ungraded” assignment in Web-CAT during lab on Wednesday. Projects sent via e-mail past the deadline at 11:59 PM will not be accepted without a universityapproved excuse. Files to submit to Web-CAT: • • UsedCar.java UsedCarList.java Specifications Overview: You have been hired by a local used car dealer to write software to provide a master list of the dealership’s inventory of used cars. The dealer, which specializes in Japanese cars, only sells Honda, Mazda, Nissan, and Toyota used cars. For this purpose, you need to design and implement a UsedCar class and UsedCarList class: (1) the UsedCar class stores basic information about the car and includes methods to set and get individual values; (2) the UsedCarList has a main method that reads used car data in from a file, creates UsedCar objects, stores the objects in an ArrayList, then prints a report (list of used cars) from ArrayList. • UsedCar.java Requirements: The dealer needs each used car item to have a stock number, the year of production, make, model, mileage, and an original price. Additionally, a reference price should be calculated based on the original price, the year, and mileage as follows: Reference Price = (X – Months/320) ×Original Price X represents for the condition of the used car based on mileage. When the mileage is 70,000 or less, X equals to 1. If the mileage is greater than 70000 but not greater than 120000, then X equals to 0.7. If the mileage is greater than 120000 then X equals to 0.45. Months is calculated as (current year – year of car) ×12. For example, months for a 2010 car would be (2012 – 2010) ×12 which is 24. Design: The UsedCar class has fields, a constructor, and methods as outlined below. (1) Fields: Instance variables for stock number, year of production, make, model, mileage, and original price (see the set methods below for types); public constants of type String with COMP 1210 Project 5: Used Car List Page 2 of 4 names HONDA (value: "Honda"), MAZDA (value: "Mazda"), NISSAN (value: "Nissan"), and TOYOTA (value: "Toyota") to represent each make. (2) Constructor: Accepts parameters for stock number, year, make, model, mileage, and original price (see the set methods below for types). (3) Methods: Usually a class provides methods to access (or read) and modify each of its instance variables (known as get and set methods) along with any other required methods. The methods for UsedCar are described below. o setStockNo: accepts a String parameter representing the stock number(six-digit number). o getStockNo: returns the stock number as an String. o setYear: accepts a int parameter representing the year of production. o getYear: returns the year of production as an int. o setMake: takes a String parameter representing the make. Changes the make and returns true only if the parameter is one of the valid categories ("Honda", "Mazda", "Nissan", or "Toyota"). o getMake: returns the brand of the used car as a String. o setModel: accepts a String parameter representing the model of the car. o getModel: returns the model as a String. o setMileage: accepts a int parameter representing the current mileages of the car. o getMileage: returns the mileage of the car. o setOriginalPrice: Takes a int parameter representing the original price. Sets the original price of the item and returns true if the value is not negative. If the value is negative, then the method should not set the original price and return a false. o getOriginalPrice: Returns the original price as an int. o calcReferencePrice: accepts no parameters and returns the reference price (a double) based on the calculations listed in the requirements. Note that you may hard code the current year as 2012. Alternatively, you could create a java.util.Date or Calendar object and then retrieve the current year from it. o toString: Your toString method should return a String representation of the UsedCar item including its stock number, year, make, model, mileage, original price, and reference price. Note that the reference price is not a field, but rather it should be calculated each time toString is invoked. It should be included in the toString return appropriately formatted and rounded to the nearest dollar. See examples below. Code and Test: As you implement your UsedCar class, you should compile and test it using interactions. For example, as soon you have implemented and successfully compiled the constructor, you should create an instance of UsedCar in interactions. Then after you implement and compile one or more methods, create a UsedCar object and invoke each of the methods you added or changed to make sure everything is working as intended. [Hint: When using interactions, you can use the Up-Arrow to avoid retyping previously entered interactions.] COMP 1210 • Project 5: Used Car List Page 3 of 4 UsedCarList.java Requirements: Although the used car dealership for which you are working will be using the UsedCar class in many of its own programs in the future, you have been requested to create a simple driver program, called UsedCarList, that will read items from a file and display them in an easily readable manner. Design: Your program should take as input the name of a file, which contains used cars data, one car per line (stock number, year, make, model, mileage, and original price). Download cars1.txt as an example. Your program should then create UsedCar objects based on the file input and add the items to an ArrayList with generic type UsedCar. Your program should count how many used cars are available of each make and display the four categories to the user with three spaces between each category. The user should then be prompted for one of the categories (1, 2, 3, 4, or 99 for all, 0 to end). The program should then print the information for each car including the reference price rounded to the nearest dollar. Your program should follow the format below exactly. Program output Prompt user for file name: cars1.txt 1. Honda(2) 2. Mazda(1) 3. Nissan(2) 4. Toyota(3) Enter Car Make(1, 2, 3, 4, or 99 for all, 0 to end): 3 Stock Number: auto0003 Year: 2006 Make: Nissan Model: 350Z Mileage: 80000 Original Price: $36,000 Reference Price: $17,100 -----------------------Stock Number: auto0007 Year: 2002 Make: Nissan Model: Altima Mileage: 130000 Original Price: $18,000 Reference Price: $1,350 -----------------------Total Number of Cars Listed: 2 1. Honda(2) 2. Mazda(1) 3. Nissan(2) 4. Toyota(3) Enter Car Make(1, 2, 3, 4, or 99 for all, 0 to end): COMP 1210 • Project 5: Used Car List Page 4 of 4 Code & Test: Your code will be tested in Web-CAT using different files, so you may want to create your own additional files for testing. There is an example of how to read from a file and insert into an ArrayList in the examples folder with the lecture notes this week. See ReverseWordsFromFile.java (download lecture notes with examples 1210 web page). For the project, you’ll need to read the data from a file (e.g., cars1.txt), create UsedCar objects, and add them to your ArrayList. To output the lists for each category, you will need an outer loop which accepts the user’s choice and an inner loop to go through the ArrayList, filtering as appropriate to produce each of the required lists of cars. ...
View Full Document

This note was uploaded on 03/02/2012 for the course COMP 1210 taught by Professor Cross during the Winter '07 term at Auburn University.

Ask a homework question - tutors are online