Hi guys, so I have this project where the requirements are as follows.
Create a class called Car, which serves to represent a particular vehicle at a car
dealership. Consider that each car has the following properties, entered by the user (all value
ranges should be error checked):
Sticker price (a decimal greater than $10,000)
Year (an integer between 2002 and 2010)
Make (a String that represents the manufacturer of the car)
Top speed (an integer between 100 and 160)
Color (a String)
Availability (a boolean that states whether the car has been sold (false) or is available (true))
The class should also contain methods that perform the following functions:
Determine whether the car is used (if the car was made before 2009)
Apply a certain discount on the sticker price
o The discount percentage should be a parameter to the method
Change a car to being sold
o This replaces the mutator method for the “availability” property
Determine the final cost of the car, considering the following:
o 8.875% sales tax
o $500 delivery fee
Output a summary of all information about the car, using a toString() method
So far I have this,
import javax.swing.JOptionPane;
public class Car
{
//*******************************************************
//Declaration of instance variables/fields of the class
//*******************************************************
private String make, color;
private int year, topSpeed;
private boolean availability;
private double stickerPrice, discount, tax;
public Car()
{
make = "";
color = "";
year = 0;
topSpeed = 0;
availability = true;
stickerPrice = 0;
discount = 0;
}
public Car(String make1, String color1, int year1, int topSpeed1, boolean availability1, double stickerPrice1, double tax1, double discount1)
{
make = make1;
color = color1;
year = year1;
topSpeed = topSpeed1;
availability = availability1;
stickerPrice = stickerPrice1;
tax = tax1;
discount = discount1;
}
//***********************************************************
//getMake()
//This method will get the make of the car.
//***********************************************************
public String getMake()
{
return make;
}
//***********************************************************
//setMake(String make)
//This method will set the make of the car.
//***********************************************************
public void setMake(String make1)
{
make = make1;
}
//***********************************************************
//getColor()
//This method will get the color of the car.
//***********************************************************
public String getColor()
{
return color;
}
//***********************************************************
//setColor(String color)
//This method will set the color of the car.
//***********************************************************
public void setColor(String color1)
{
color = color1;
}
//***********************************************************
//getYear()
//This method will get the year that the car was made.
//***********************************************************
public int getYear()
{
return year;
}
//***********************************************************
//setYear(int year1)
//This method will set the year in which the car was made.
//***********************************************************
public void setYear(int year1)
{
year = year1;
}
//***********************************************************
//getTopSpeed()
//This method will get the top speed of the car.
//***********************************************************
public int getTopSpeed()
{
return topSpeed;
}
//***********************************************************
//setTopSpeed(int topSpeed1)
//This method will set the top speed of the car.
//***********************************************************
public void setTopSpeed(int topSpeed1)
{
topSpeed = topSpeed1;
}
//***********************************************************
//getAvailability()
//This method will get the availabilty of the car.
//***********************************************************
public boolean getAvailability()
{
return availability;
}
//***********************************************************
//setMake(String make)
//This method will set the make of the car.
//***********************************************************
public void setAvailability(boolean availability1)
{
availability = availability1;
}
//***********************************************************
//getStickerPrice()
//This method will get the sticker price of the car.
//***********************************************************
public double getStickerPrice()
{
return stickerPrice;
}
//***********************************************************
//setStickerPrice(double stickerPrice)
//This method will set the sticker price of the car.
//***********************************************************
public void setStickerPrice(double stickerPrice1)
{
stickerPrice = stickerPrice1;
}
//***********************************************************
//getTax()
//This method will get the tax on the car.
//***********************************************************
public double getTax()
{
return tax;
}
//***********************************************************
//setMake(String make)
//This method will set the tax on the car.
//***********************************************************
public void setTax(double tax1)
{
tax = tax1;
}
//***********************************************************
//getDiscount()
//This method will get the discount on the car.
//***********************************************************
public double getDiscount()
{
return discount;
}
//***********************************************************
//setDiscount(double discount1)
//This method will set the discount on the car.
//***********************************************************
public void setDiscount(double discount1)
{
discount = discount1;
}
//************************************************************
//used()
//This method if the car is used or not.
//************************************************************
public void used(int year)
{
if (year < 2009)
{
JOptionPane.showMessageDialog("The car is used.");
}
else
JOptionPane.showMessageDialog("The car is new.");
}
//***************************************************************
//discount(int percentOff)
//This method puts a discount on the sticker price.
//***************************************************************
public double discount(int percentOff)
{
percentOff *= .01;
stickerPrice = (stickerPrice*percentOff);
return stickerPrice;
}
public double totalCost(int stickerPrice, int discount)
{
}
}
Sorry about all the commenting in the code, but I find it helps a lot. By the way, this is supposed to be a stand alone class. I'll have to write a driver for it later.
I'm not exactly sure how I'd go about to calculate the final cost or how to change the availability.
Also, an error that I'm getting is that the JOptionPane isn't being found.
Thanks for the help guys, I really really do appreciate it.