Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Car Lot Gui Goal You are to write a WidgetViewer program that will allow Sophie, Sally and Jack to operate the inventory of their car

Car Lot Gui

Goal

You are to write a WidgetViewer program that will allow Sophie, Sally and Jack to operate the inventory of their car dealership. They need to add and remove cars to and from their car lot inventory and display them. This document will describe the minimum expected function for a grade of 90. Your mission is to go and do better. The meaning of better is largely up to you. For example, you might add new fields to the Car objects --- make, model, and year. Or, you might add more sort capabilities to the Car Lot, allowing the GUI to display cars sorted by price. Be creative; find something that stinks about the program as described here, and fix it.

Should you decide to use language elements that we havent covered, you should be prepared to explain how your program works in detail, and in person. You may, under no circumstances, use a code generator. Like all WidgetViewer programs, controlling the layout of our widgets is awkward. Assuming the layout is readable, the grading will not penalize a program for an awkward layout.

Objectives

By the end of this project the student will be able to:

Write a WidgetViewer program that maintains a set of Cars in a car salesmans car lot, identify specific cars -- those with the highest mileage or best miles per gallon, adding cars, selling cars, for instance.

Write a program consisting of multiple classes and multiple objects based on those classes.

Demonstrate the ability to segregate business logic from user interface code.

Demonstrate the ability to catch user events, write event handlers, listen for events, and process events.

Manage a collection of car objects.

Sort collections of objects.

Change a cars state (from not sold to sold)

Grading Elements

Your program should:

Follow your instructors rules and conventions for code quality, conventions and submission

Be a WidgetViewer program that allows GUI control of the Car Lot and individual Car information

Use event handlers to indicate a user clicking a button to add or sell cars

Allow a user to add a car with a given identifier, initial mileage and fuel consumption in miles per gallon (MPG), the cost of acquiring the new car, and the price the new car will be sold for. All new cars have a status of is not sold

Be implemented as multiple classes with multiple instances of some classes

Remove or sell a car from the inventory using its identifier, changing its status from is not sold to is sold and adding a field for profit where profit made is displayed.

Display the lots inventory both in the order that the cars were entered and in the order of worst-MPG to best-MPG.

Display the car with the best MPG and the highest mileage.

Display the average miles per gallon for the entire fleet

Display profit (price - cost) from sold cars

Improve the described programprovided are some suggestions with the possible number of points that can be earned:

Save and restore. Ability to save the cars in the car lot to a text file and the associated ability to read the text file and add those cars to the car lot 15 points

Sort field capability. Permit the user to specify which car attribute should be used to populate sorted text area. Use should be able to specify any one of the Car attributes and whether the sort should be ascending/descending. 15 points

Format output: Modify the output format of the two text areas to be columinar. Each column should have a heading and the values justified (strings left justified, numeric values right justified). Format money values with a leading dollar sign and two decimal places and separating commas (for example $12,345.67). MPG should have 1 decimal place, and Miles have separating commas. 10 points

Error checking. Validate all numeric input. Any error in data entry or illogical value (e.g., negative values) should result in an error message being displayed. The user should have the opportunity to correct any errors or to back out the action. Error checking logic should utilize try/catch structures. 10 points

Supply a Word document that addresses any enhancement that you make to the project. In that document provide a brief description of the enhancement, an overview of code changes that you made and annotated screenshots which illustrate the enhancement. Please note, the number of points you receive are in large part determined by the information you provide in this document.

If you wish to make other enhancements you may want to contact me and describe the change so that I can give you an idea of the number of points you could earn.

The maximum grade that you can receive on the project is 140 (e.g., up to 40 points extra credit above the value of the project (100 points). Since the project represents 20% of your grade, this extra credit can potentially add 8% to your overall average (almost a full grade).

Sample Execution

The initial panel has fields for adding a new car to the fleet -an identification field, current mileage, fuel consumed, cost and price. It has a field for removing a sold car from the fleet -identification. It also has (empty) best MPG, highest mileage, fleet MPG and profit fields. There are two text areas, one for the lot with the cars in the order they were entered, the other with cars listed from worst to best MPG

image text in transcribed

Figure 1. Initial Panel

First, lets buy our first car to put up for sale in our car lot.

image text in transcribed

Figure 2. Entering Edsel

Next, lets Click the make a new car button.

image text in transcribed

Figure 3. Lot with One Car for sale.

We have one car, lets purchase another to put up for sale on our lot.

image text in transcribed

Figure 4. Entering Yugo

Lets Click the make a new car button.

image text in transcribed

Figure 5. Lot with Two Cars for sale.

Well skip separate pictures of entering cars for the next figure -- you get the idea.

image text in transcribed

Figure 6. Lot with 4 Cars.

Note the CarLot as entered vs. CarLot by MPG, as well as the labels for best MPG, highest mileage and fleet avg MPG and how they change with added cars.

Next, lets see what happens when we sell a car.

image text in transcribed

Figure 7. Selling Edsel

We have not yet recorded the sale. Click the Press to record sale button.

image text in transcribed

Figure 8. Edsel Sold.

Note that this car still remains in the lot inventory, but its status changes from is not sold to is sold. Also note that the profit label has increased from 0 to 5000. Lets sell another.

image text in transcribed

Figure 9 Selling Prius

We have not yet recorded the sale. Click the Press to record sale button.

image text in transcribed

Figure 10. Prius Sold.

Note that the profit label has increased from 5000 to 11000. Also note that each car in the inventory list shows how much profit is attributed to the sale of each car. Edsel profit=5000, Prius profit=6000.

Car.java

public class Car { private int cost; private String identifier; private boolean isSold = false; private int milage; private double mpg; private int price; public Car() { identifier = ""; milage = 0; mpg = 0; cost = 0; price = 0; } public Car(String identifier) { this.identifier = identifier; milage = 0; mpg = 0; cost = 0; price = 0; } public Car(String identifier, int milage, double mpg, int cost, int price) { this.identifier = identifier; this.milage = milage; this.mpg = mpg; this.cost = cost; this.price = price; } public void addMiles(int miles) { milage += miles; } public int compareId(Car o) { return identifier.compareTo(o.identifier); } public int compareMPG(Car otherCar) { double myMPG = getMPG(); double otherMPG = otherCar.getMPG(); if (myMPG == otherMPG) return 0; if (myMPG - otherMPG > 0) return 1; return -1; } public int compareMiles(Car otherCar) { return getMilage() - otherCar.getMilage(); } public int comparePrice(Car o) { return price - o.price; } public int getCost() { return cost; } public String getIdentifier() { return identifier; } public int getMilage() { return milage; } public double getMPG() { return mpg; } public int getPrice() { return price; } public int getProfit() { if (isSold) return price - cost; return 0; } public boolean isSold() { return isSold; } public void setCost(int cost) { this.cost = cost; } public void setIdentifier(String identifier) { this.identifier = identifier; } public void setMiles(int milage) { this.milage = milage; } public void setMPG(double mpg) { this.mpg = mpg; } public void setPrice(int price) { this.price = price; } public void setSold(boolean isSold) { this.isSold = isSold; } @Override public String toString() { String soldProfit = "is sold, profit=" + getProfit(); if (!isSold()) soldProfit = "is not sold"; return "Car id=" + identifier + ", milage=" + milage + ", mpg=" + mpg + ", cost=" + cost + ", price=" + price + ", " + soldProfit + " "; } }

CarLot.java

import java.util.ArrayList; public class CarLot { private ArrayList myCars; public CarLot() { myCars = new ArrayList(); } public boolean add(Car carToAdd) { return myCars.add(carToAdd); } public Car find(String identifier) { for (Car c: myCars) { if (c.getIdentifier().equals(identifier)) { return c; } } return null; } public Car get(int position) { return myCars.get(position); } public double getCarAverageMPG() { if (size() == 0) return -1; double totMPG = 0; for (Car c: myCars) { totMPG += c.getMPG(); } return totMPG / myCars.size(); } public Car getCarBestMPG() { if (myCars.isEmpty()) return null; Car car = myCars.get(0); for (Car c: myCars) { if (c.getMPG() > car.getMPG()) car = c; } return car; } public Car getCarHighestMilage() { if (myCars.isEmpty()) return null; Car car = myCars.get(0); for (Car c: myCars) { if (c.getMilage() > car.getMilage()) car = c; } return car; } public int getProfit() { int profit = 0; for (Car c: myCars) { profit += c.getProfit(); } return profit; } public ArrayList getSortedByMPG() { ArrayList newList = new ArrayList(myCars); selectionSort(newList); return newList; } public int getTotalMiles() { int totalMiles = 0; for (Car c: myCars) { totalMiles += c.getMilage(); } return totalMiles; } private void selectionSort(ArrayList list) { for (int i = 0; i  

new car mileage new car price [highest mileage none] fleet avg MPG-1.0] new car id MPG Sold Car ld new car cost Press to record sale make a new car [best MPG none] profit: 0 CarLot as entered CarLot [ CarLot by MPG new car mileage new car price [highest mileage none] fleet avg MPG-1.0] new car id MPG Sold Car ld new car cost Press to record sale make a new car [best MPG none] profit: 0 CarLot as entered CarLot [ CarLot by MPG

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

A Complete Guide To Data Science Essentials

Authors: Miguel

1st Edition

9358684992, 978-9358684995

More Books

Students also viewed these Databases questions

Question

1. Describe the types of power that effective leaders employ

Answered: 1 week ago