CSE 1302J - Project # 4

Inheritance and Files

 

 

Design and code a class called Date that includes two integer instance variables, day and year, and a String variable called month.  Include a parameterized constructor, toString, and equals method.

 

Design and code a class called Car that includes the following instance variables: double dealerCost, integer idNumber, Date dateArrived, integer modelYear, and String makeModel.  You should have a parameterized constructor, toString, and equals method (have the same modelYear, dateArrived, and makeModel).

 

Design and code a class called SoldCar that is derived from Car.  Add the instance variables of double price, String customer, and Date dateSold.  Include two constructor methods – one that allows the user to have eight arguments (dealerCost, idNumber, dateArrived, modelYear, make, price, customer, dateSold) and one that allows the user to have four arguments (someCar, price, customer, and dateSold).  SoldCar should also have a toString method, an equals method (have the same modelYear, dateArrived, makeModel, and dateSold) and calculateProfit method.

 

Your code should run with a data file of Car and SoldCar objects.  Define the text file according to Chapter 11 – do not use Scanner class.  Read all the data and put the Car and SoldCar objects into an array.  Test to see if any Car or SoldCar objects added to the array are equal (similar) (same modelYear, dateArrived, and make for Car objects – same modelYear, dateArrived, make and dateSold for SoldCar objects) to ones already in the array.  Print the idNumbers of similar cars.  This can be done once with a double loop at the end of main. 

 

Use a trailer read while loop to solve this problem.  Use an ArrayList or your own design of a array list for the array that holds the Car and SoldCar objects.  Remember that when you retrieve an object from an ArrayList (get method), you must cast it before assigning it to a storage location. 

 

Read the code first.  While the code is not X, do the following:

            If code is C - 7 variables follow to create a Car object.  If it is not an error record (same idNumber as another car in the array), add it to the array, and check for similar makes and models (print those idNumbers).

                S1 – indicates an idNumber followed by 5 variables to make that Car (idNumber) a SoldCar.  Look up that car in the array and make it a SoldCar and store back in array

                S2 - 12 variables follow to create a SoldCar object.  If it is not an error (same idNumber), add it to the array and check for similar makes and models (print those idNumbers).

     X – end of file

Each time you are about to add an object to the array, check to see if there is an object with the same idNumber in the array.  Print an error message if there is a duplicate idNumber.  You will also be checking to see if there are similar (equals method) Car or SoldCar objects as you add new objects to the array.  Just print the IdNumbers of similar objects.  This can be done once with a double loop at the end of main. 

 

When the data file has all been read, print out the ArrayList or the array holding your data. – if printing a SoldCar, also print the profit made on the car.  The SoldCar toString() method can call the calcProfit() method.  Profit does not have to be another instance variable.

 

Include a UML chart in the folder for this program – no algorithms this time.

 

 

 

Data File:

C 5000.00 1234 January 1 2004 2000 Honda_Accord

S1 1234 6000.00 Roth February 15 2004

S2 8000.00 2222 January 15 2004 1999 Ford_F150 9500.00 Jones January 25 2004

C 14000.00 3333 June 6 2003 1999 GMC_Suburban

C 5000.00 1222 January 1 2004 2000 Honda_Civic

C 10000.00 4444 July 10 2002 2001 Toyota_Tundra

S2 12000.00 5555 February 6 2003 1965 Ford_Mustang 15000 Williams September 4 2003

S1 3333 15650 Brown December 25 2003

C 10500.00 4000 July 10 2002 2001 Toyota_Tundra

S2 9500.00 6666 January 21 2004 1999 Ford_F150 9000.00 Smith January 31 2004

C 5000.00 1222 January 1 2004 2000 Honda_Civic

S2 8000.00 2222 January 15 2004 1999 Ford_F150 9500.00 Jones January 25 2004

S2 9900.00 6667 January 21 2004 1999 Ford_F150 9007.00 Byrd January 31 2004

X

 

 

 

    • 10 years ago
    Complete A++ Solution
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      answer.zip