Assignment is not due until Thursday. Any guidance in the right direction would be greatly appreciated. Have basic knowledge of classes, inheritance, interfaces, files, and arrays.
CS 1450 Data Structures and Algorithms Spring 2019 Assignment #4 Due Date: Feb 20, 2019 at 12:15pm (MW class), Feb 21, 2019 at 9:25am or 4:45pm (TR classes) Purpose Effort: Points: Deliverables: Upload a .zip file with ONLY your source code (the one java file) to Canvas. Learn to use objects that contain objects, collections, and more practice with interfaces Individual 100 Hand in a hardcopy version of the code and your design notes at beginning of class. Assignment Description This assignment provides more practice creating and manipulating classes and interfaces as well as the opportunity to use Java's Comparable interface. For this assignment, create a program that models a Carvana Car Vending Machine. Browse to the link https://www.carvana.com/vendingmachine to see an example of the vending machine tower this assignment will model. Your vending machine will contain one tower of cars. The size of the tower- that is-the number of columns and slots in each column, is specified in the VendingMachineCors.txt file To setup the vending machine's tower of cars, read the number of slots and columns from the file and create a car tower based on these values. Next, for each car in the file, read its details, create the car, and place the car into the vending machine into its specified slot and column. Note, not all locations in the vending machine's tower will contain a car. For example, in the test file shown below, column 1 slots 3 and 4 are empty, column 2 slots 2 and 4 are empty, and column 3 slots 1, 4 and 5 are empty After all cars are placed into the vending machine, display the loaded vending machine and then print an inventory report. The inventory report must display the cars in order from lowest price to highest price. Specifications 1. Create a Java class called LastNameFirstN 2. Follow "CS1450 Programming Assignments Policy 3. Write a test program (i.e. main) to do the following . Step 1: Create a vending machine object o Contains a tower of cars (2D array) with the number of slots&columns read from file. Step 2: Load vending machine with all cars in the file o For each car in the file: o o o Read details for the car from the file. Create a car object using the details. Add car to vending machine's tower in slot and column specified in file o Use the addCarToTower method in the VendingMachine class .Step 4: Display the loaded vending machine. o Display a nicely formatted version of the vending machine o Use the displayCars() method in the VendingMachine class Step 3: Print an inventory report for the vending machine. Write a method to print report: public static void printInventory (VendingMachine vendingMachine) This method must: .Be placed In your Asslgnment4 class .Create one VehicleReport for each car and place all reports into an ArrayList Sort all VehicleReports in the ArrayList using the Collections.sort() method Print all VehicleReports in the ArrayList (which are now sorted by price) Call the print() method on VehicleReport (see 2 output example) 4. Test file information Run your code on the provided file VendingMachineCars.txt This file is an example so DO NOT assume that your code should only work for a car tower with 6 slots and 5 columns and/or these cars in this specific order. The grader file ill be different. a. Number of slots in the tower (array row index) Number of columns in tower (array column index) 1 129400.00 2015 Toyota Tacoma 12 31700.00 2012 BMW 6Series 1 541700.00 2016 Ford Mustang 2 1 31000.00 2017 BMW X1 2 3 14300.00 2015 Nissan Altima 25 17900.00 2016 Dodge Challenger 3 2 26000.00 2017 MIni Convertible 3 3 39600.00 2017 Cheyrolet Tahoe 4 115100.00 2014 Chevy Volt 4 2 24400.00 2017 Toyota Rav4 4 3 30400.00 2017 Subaru Outback 4 4 72900.00 2017 Tesla Model-S 45 43500.00 2016 Porsche Cayenne Details for each car Note -Column 0 and Slot 0 are NOT used - Column 1: slots 3 & 4 are empty - Column 2: slots 2 & 4 are empty - Colurnn 3: slots 1,4 & 5 are empty Column 4: no empty slots b. 1* line is the number of slots that each column contains c. 2r ine is the number of columns in the vending machine's tower d. Remaining lines contain details for each car. The format is as follows: Column#Slot# Price Year Manufacturer Model 1 1 29400.00 2015 Toyota Tacoma Interfaces and Classes Printable Interface . Descrption o This interface represents an object's ability to print details about itself Public Methods o print) -returns string with details object wants to display in a nice format VendingMachine Class Description Represents the vending machine of cars. The vending machine contains one car tower that is modeled by a 2-dimensional array If you "flatten" the car tower it can be viewed as a 2D array of car objects. o I'm using the word "slot" instead of "row" since slot makes more sense when talking about placing a car in the tower, so slot row in this assignment. . Slot 0 and column 0 are not used They are still part of 2D array, but we won't be placing cars Into them. . In the test file, the tower has 6 slots (0-5) and 5 columns (0-4) . BUT the car tower is represented ONLY by slots 1-5 and columns 1-4 in the array as shown: Column 0 Column 1 Column 2 Column 3 Column 4 Slot 0 Slot 1 Slot 2 Slot 3 Slot 4 Slot 5 Toyota BMW BMWW Mini Ch To Subaru Tesla Porsche Nissan Ford Dod . Private Data Fields o numberSlots-number of slots in each column (i.e. row index) o numberColumns-number of columns in the vending machine (.e. column index) o carTower- array of Car objects use a 2D array NOT ArrayList - see FAQ for help with 2D arrays Public Methods o Constructor: public VendingMachine (int numberSlots, int numberColumns) Initializes numberSlots and numberColumns to incoming values Initializes size of car tower (2D array) to numberSlots and numberColumns carTower new Car[numberSlots] [numberColumns]; Getters: For data fields numberSlots and numberColumns Setters: None o o o addCarToTower (int slotNumber, int columnNumber, Car car) -Places incoming car object in 2D array at a specified location (slot/column) SImulates loading a car into the vending machine in a speclfic locatlon o getCar (int slot, int column) Returns the car stored in the tower (2D array) at the speclfic slot/column If there is no car in slot/column location (i.e. empty array location), returns null o displayCars() Displays a nicely formatted version of the vending machine's tower (2D array) -print slot #, column #, and car manufacturer (see 1g example output below) Car Class Description o Represents one car Private Data Fields o price double value for the car's sticker price o year-integer value for the car's year o manufacturer string value for the car's manufacturer o model - string value for the car's model . Public Methods o Constructor public Car (double price, int year, String manufacturer, String model) inltializes all private data fields with Incoming values o Getter: One for each data field Setters: None VehicleReport Class Description oRepresents the report for one vehicle. o Contains slot number, column number, year, manufacturer, model, and price. o Class must implement Printable and Comparable
Private Data Fields slotNumber-slot # vehicle is stored in (ie, array row index) columnNumber-column # vehicle is stored in (i.e. array column index) price -double value for vehicle's sticker price year- integer value for the vehicle's year o manufacturer string value for the vehicle's manufacturer o model string value for the vehicle's model o o o . Public Methods o Constructor public VehicleRecord (int slotNumber, int columnNumber, double price, int year, String manufacturer, String model) initializes all private data fields with Incoming values Getters and Setter: None public String print)-overrides method in Printable interface o returns string with column#, slot#, year, manufacture, model, and price o public int compareTofVehicleReport otherReport)- overrides method in Comparable returns integer value (-1, 0, 1) based on result of comparing tvo vehicle reports Compares two vehicle reports based on the price Mut Do and Tips Must Do . . . Use a regular 2D array to model the vending machine's car tower (see FAQ on 2D arrays) Use an ArrayList to store vehicle reports Use Java's pre-defined Comparable interface. Do not create your own Comparable Interface! Tip: Reading Cars from File The number of cars is not part of the file as on previous assignments. On this assignment, usea while loop that reads until the end of the file is reached using the scanner's hasNext method. . Tip: Slots and Columns Slot zero and column zero is not used in the 2D array. They are part of the array but not used. Not al locations in the vending machine's tower contain a car o Empty locations in the array contain the value null Tip: VehicleReport Sorting and Comparable In printInventory method, use the sort method on the Collections class. Here's how this works: . Because VehicleReport implements Comparable, the class must contain a compareTo method. The compareTo will compare two reports based on vehicle price. o The connection to Collections.sort() method: Collections.sort uses an object's compareTo method to compare and sort objectsl By sending the ArrayList of VehicleReports to Collections.sort, the ArrayList is sorted based on vehicle price. See Listing 13.9 p. 515 in Liang for compareTo example One way to return nicely formatted strings in the print methods-use string format method. For example ("%d\tM\t%-4d\t%-10s \t%-15s\t%-1.2f", columnNumber, slotNumber, year, manufacturer, model, price); return String o See chapter 4 in your book for details on format specifiers r output will look like the following when running against the test file VendingMachineCars.txt ding cars into vending machine... Column 1 Column 2 BMW Nissan Dodge Column 3 Column 4 Toyota t 1 t 2 Chevy Toyota Subaru Tesla Porsche Mini Chevy t 4 t 5 Dashes represent an empty slot in tower Produced using print method on VehicleReport VENDING MACHING INVENTORY (From Low to High Price) Lumn Slot Year Manufacturer Model Price 2015 Nissan 2014 Chevy 2016 Dodge 2817 Toyota 2017 Mini 2015 Toyota 2017 Subaru 2017 BMl 2812 BM 2017 Chevy 2016 Ford 2016 Porsche 2017 Tesla Altima 2014 Volt Challenger Rav4 Convertible Tacoma Outback X1 6Series Tahoe Mustang Cayenne Model-S 24409.90 29400. 30400.00 31768.66 72966.96e CS 1450 Data Structures and Algorithms Spring 2019 Assignment #4 Due Date: Feb 20, 2019 at 12:15pm (MW class), Feb 21, 2019 at 9:25am or 4:45pm (TR classes) Purpose Effort: Points: Deliverables: Upload a .zip file with ONLY your source code (the one java file) to Canvas. Learn to use objects that contain objects, collections, and more practice with interfaces Individual 100 Hand in a hardcopy version of the code and your design notes at beginning of class. Assignment Description This assignment provides more practice creating and manipulating classes and interfaces as well as the opportunity to use Java's Comparable interface. For this assignment, create a program that models a Carvana Car Vending Machine. Browse to the link https://www.carvana.com/vendingmachine to see an example of the vending machine tower this assignment will model. Your vending machine will contain one tower of cars. The size of the tower- that is-the number of columns and slots in each column, is specified in the VendingMachineCors.txt file To setup the vending machine's tower of cars, read the number of slots and columns from the file and create a car tower based on these values. Next, for each car in the file, read its details, create the car, and place the car into the vending machine into its specified slot and column. Note, not all locations in the vending machine's tower will contain a car. For example, in the test file shown below, column 1 slots 3 and 4 are empty, column 2 slots 2 and 4 are empty, and column 3 slots 1, 4 and 5 are empty After all cars are placed into the vending machine, display the loaded vending machine and then print an inventory report. The inventory report must display the cars in order from lowest price to highest price. Specifications 1. Create a Java class called LastNameFirstN 2. Follow "CS1450 Programming Assignments Policy 3. Write a test program (i.e. main) to do the following . Step 1: Create a vending machine object o Contains a tower of cars (2D array) with the number of slots&columns read from file. Step 2: Load vending machine with all cars in the file o For each car in the file: o o o Read details for the car from the file. Create a car object using the details. Add car to vending machine's tower in slot and column specified in file o Use the addCarToTower method in the VendingMachine class .Step 4: Display the loaded vending machine. o Display a nicely formatted version of the vending machine o Use the displayCars() method in the VendingMachine class Step 3: Print an inventory report for the vending machine. Write a method to print report: public static void printInventory (VendingMachine vendingMachine) This method must: .Be placed In your Asslgnment4 class .Create one VehicleReport for each car and place all reports into an ArrayList Sort all VehicleReports in the ArrayList using the Collections.sort() method Print all VehicleReports in the ArrayList (which are now sorted by price) Call the print() method on VehicleReport (see 2 output example) 4. Test file information Run your code on the provided file VendingMachineCars.txt This file is an example so DO NOT assume that your code should only work for a car tower with 6 slots and 5 columns and/or these cars in this specific order. The grader file ill be different. a. Number of slots in the tower (array row index) Number of columns in tower (array column index) 1 129400.00 2015 Toyota Tacoma 12 31700.00 2012 BMW 6Series 1 541700.00 2016 Ford Mustang 2 1 31000.00 2017 BMW X1 2 3 14300.00 2015 Nissan Altima 25 17900.00 2016 Dodge Challenger 3 2 26000.00 2017 MIni Convertible 3 3 39600.00 2017 Cheyrolet Tahoe 4 115100.00 2014 Chevy Volt 4 2 24400.00 2017 Toyota Rav4 4 3 30400.00 2017 Subaru Outback 4 4 72900.00 2017 Tesla Model-S 45 43500.00 2016 Porsche Cayenne Details for each car Note -Column 0 and Slot 0 are NOT used - Column 1: slots 3 & 4 are empty - Column 2: slots 2 & 4 are empty - Colurnn 3: slots 1,4 & 5 are empty Column 4: no empty slots b. 1* line is the number of slots that each column contains c. 2r ine is the number of columns in the vending machine's tower d. Remaining lines contain details for each car. The format is as follows: Column#Slot# Price Year Manufacturer Model 1 1 29400.00 2015 Toyota Tacoma Interfaces and Classes Printable Interface . Descrption o This interface represents an object's ability to print details about itself Public Methods o print) -returns string with details object wants to display in a nice format VendingMachine Class Description Represents the vending machine of cars. The vending machine contains one car tower that is modeled by a 2-dimensional array If you "flatten" the car tower it can be viewed as a 2D array of car objects. o I'm using the word "slot" instead of "row" since slot makes more sense when talking about placing a car in the tower, so slot row in this assignment. . Slot 0 and column 0 are not used They are still part of 2D array, but we won't be placing cars Into them. . In the test file, the tower has 6 slots (0-5) and 5 columns (0-4) . BUT the car tower is represented ONLY by slots 1-5 and columns 1-4 in the array as shown: Column 0 Column 1 Column 2 Column 3 Column 4 Slot 0 Slot 1 Slot 2 Slot 3 Slot 4 Slot 5 Toyota BMW BMWW Mini Ch To Subaru Tesla Porsche Nissan Ford Dod . Private Data Fields o numberSlots-number of slots in each column (i.e. row index) o numberColumns-number of columns in the vending machine (.e. column index) o carTower- array of Car objects use a 2D array NOT ArrayList - see FAQ for help with 2D arrays Public Methods o Constructor: public VendingMachine (int numberSlots, int numberColumns) Initializes numberSlots and numberColumns to incoming values Initializes size of car tower (2D array) to numberSlots and numberColumns carTower new Car[numberSlots] [numberColumns]; Getters: For data fields numberSlots and numberColumns Setters: None o o o addCarToTower (int slotNumber, int columnNumber, Car car) -Places incoming car object in 2D array at a specified location (slot/column) SImulates loading a car into the vending machine in a speclfic locatlon o getCar (int slot, int column) Returns the car stored in the tower (2D array) at the speclfic slot/column If there is no car in slot/column location (i.e. empty array location), returns null o displayCars() Displays a nicely formatted version of the vending machine's tower (2D array) -print slot #, column #, and car manufacturer (see 1g example output below) Car Class Description o Represents one car Private Data Fields o price double value for the car's sticker price o year-integer value for the car's year o manufacturer string value for the car's manufacturer o model - string value for the car's model . Public Methods o Constructor public Car (double price, int year, String manufacturer, String model) inltializes all private data fields with Incoming values o Getter: One for each data field Setters: None VehicleReport Class Description oRepresents the report for one vehicle. o Contains slot number, column number, year, manufacturer, model, and price. o Class must implement Printable and Comparable Private Data Fields slotNumber-slot # vehicle is stored in (ie, array row index) columnNumber-column # vehicle is stored in (i.e. array column index) price -double value for vehicle's sticker price year- integer value for the vehicle's year o manufacturer string value for the vehicle's manufacturer o model string value for the vehicle's model o o o . Public Methods o Constructor public VehicleRecord (int slotNumber, int columnNumber, double price, int year, String manufacturer, String model) initializes all private data fields with Incoming values Getters and Setter: None public String print)-overrides method in Printable interface o returns string with column#, slot#, year, manufacture, model, and price o public int compareTofVehicleReport otherReport)- overrides method in Comparable returns integer value (-1, 0, 1) based on result of comparing tvo vehicle reports Compares two vehicle reports based on the price Mut Do and Tips Must Do . . . Use a regular 2D array to model the vending machine's car tower (see FAQ on 2D arrays) Use an ArrayList to store vehicle reports Use Java's pre-defined Comparable interface. Do not create your own Comparable Interface! Tip: Reading Cars from File The number of cars is not part of the file as on previous assignments. On this assignment, usea while loop that reads until the end of the file is reached using the scanner's hasNext method. . Tip: Slots and Columns Slot zero and column zero is not used in the 2D array. They are part of the array but not used. Not al locations in the vending machine's tower contain a car o Empty locations in the array contain the value null Tip: VehicleReport Sorting and Comparable In printInventory method, use the sort method on the Collections class. Here's how this works: . Because VehicleReport implements Comparable, the class must contain a compareTo method. The compareTo will compare two reports based on vehicle price. o The connection to Collections.sort() method: Collections.sort uses an object's compareTo method to compare and sort objectsl By sending the ArrayList of VehicleReports to Collections.sort, the ArrayList is sorted based on vehicle price. See Listing 13.9 p. 515 in Liang for compareTo example One way to return nicely formatted strings in the print methods-use string format method. For example ("%d\tM\t%-4d\t%-10s \t%-15s\t%-1.2f", columnNumber, slotNumber, year, manufacturer, model, price); return String o See chapter 4 in your book for details on format specifiers r output will look like the following when running against the test file VendingMachineCars.txt ding cars into vending machine... Column 1 Column 2 BMW Nissan Dodge Column 3 Column 4 Toyota t 1 t 2 Chevy Toyota Subaru Tesla Porsche Mini Chevy t 4 t 5 Dashes represent an empty slot in tower Produced using print method on VehicleReport VENDING MACHING INVENTORY (From Low to High Price) Lumn Slot Year Manufacturer Model Price 2015 Nissan 2014 Chevy 2016 Dodge 2817 Toyota 2017 Mini 2015 Toyota 2017 Subaru 2017 BMl 2812 BM 2017 Chevy 2016 Ford 2016 Porsche 2017 Tesla Altima 2014 Volt Challenger Rav4 Convertible Tacoma Outback X1 6Series Tahoe Mustang Cayenne Model-S 24409.90 29400. 30400.00 31768.66 72966.96e