Java Programming Assignment Task: The code provided in this assignment is a clas
ID: 674565 • Letter: J
Question
Java Programming Assignment
Task: The code provided in this assignment is a class used by very basic product inventory management system. The project is still in development, but has reached a point in the design that the Product class provided contains core information that is considered solid. In other words, the properties and behaviors of the class are not changing anytime soon.
In a separate, but parallel, project effort, you have been assigned the task of creating a basic program prototype that handles reading specific automotive information from a user and displays data captured. The project lead wants to reuse code as much as possible as there may be opportunities later to use this class infrastructure on other projects.
Given all this, your task is to create the prototype with a simple main program and a class that reuses (inherits from) the Product class used in the product inventory management system. Your prototype must ask the following from the user:
1) Add new car information
2) Display all cars
All Cars have an alphanumeric ID, make, model, year and selling price. User's entering new car information do not have to account for spaces in the make and model. Year should be a number from 1960 to 2020. Selling price must be at least 10,000.
When displaying all cars entered, simply show all attributes of each car. There are opportunities for other car program options (finding a specific car by ID, showing average selling price of all cars, removing or updating car information, etc.). These can be included as extra credit options but only if the 2 basic required options are working first.
The Car class must use inheritance from the Product class. Thus, in your project, you will need to make sure you bring in the Product class as shown here as its own class file. You will also notice that there are ranges for year and selling price. You must have basic error checking to handle years and selling prices out of range (and remember that you cannot have direct communication with the user from the Car class). The product class also must not be changed in any way.
If you are using python or any other OO language, make the necessary adjustments to create a Product class that is the same as the one provided here to demonstrate creating a Car class that uses inheritance in that language.
Code:
public class Product
{
private String id;
private double sellingPrice;
public Product()
{
id = "TBD";
sellingPrice = 0.0;
}
public Product(String i, double p)
{
id = i;
sellingPrice = p;
}
public void setSellingPrice(double p)
{
sellingPrice = p;
}
public void setId(String i)
{
id = i;
}
public String getId()
{
return id;
}
public double getSellingPrice()
{
return sellingPrice;
}
public String toString()
{
return String.format("ID: %s Selling Price: $%.2f ", id, sellingPrice);
}
}
Explanation / Answer
public class Car extends Product{
private String make;
private String model;
private int year;
public Car(String ID,String ma,String mo,int y,double price){
super(ID,price);
if(price<10000){
setSellingPrice(10000);
}if(y<1960||y>2020){
year=2000;
}else{
year=y;
}
make=ma;
model=mo;
}
public String getMake(){
return make;
}
public String getModel(){
return model;
}
public int getYear(){
return year;
}
public String toString(){
return super.toString()+"Make: "+getMake()+" Model: "+getModel()+" Made in year: "+getYear();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.