Question
java not javascript Add a class named SuperCar that extends our Auto class. Add two fields, int maxSpeed and int value. Finish out the blueprint.
java not javascript
Add a class named SuperCar that extends our Auto class. Add two fields, int maxSpeed and int value. Finish out the blueprint.
SuperCars cost $50.00 per day. Make that change to the code. NOTE: regular cars need to stay at $15.00 per day.
Add two SuperCars to the ArrayList in the loadNewData() method.
Now the program should also offer these two super cars as well as the others.
public class Auto {
// the Auto class has two fields
private int year;
private String make;
private String model;
private String vin;
private double miles;
// empty constructor
public Auto()
{
}
// full constructor
public Auto(int year, String make, String model, String vin, double miles) {
this.year = year;
this.make = make;
this.model = model;
this.vin = vin;
this.miles = miles;
}
// toString method (the wording does not make sense until you realize
// that you will be calling this after calling the customer toString method
public String toString()
{
return "a " + year + " " + make + " " + model +
" with a VIN# of " + vin + " and a mileage of " + miles;
//return "a car with a vin of " + vin + " and a mileage of " + miles;
}
// getters and setters
public double getMiles() {
return miles;
}
public void setMiles(double miles) {
this.miles = miles;
}
public String getVin() {
return vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
}
public class Customer {
// the Customer class has three fields
private int custId;
private String name;
private boolean goldDude;
// the following will be used to automatically generate customer ids
//so they will be unique
private static int nextNum = 100;
// empty constructor
public Customer()
{
custId = nextNum;
nextNum++;
}
// constructor for creating a new customer where the id is
// automatically created
public Customer(String n)
{
name = n;
custId = nextNum;
nextNum++;
}
// full constructor
public Customer( String n, boolean gcm)
{
custId = nextNum;
nextNum++;
name = n;
goldDude = gcm;
}
// toString method
public String toString()
{
return name + " (custID: " + custId + ")";
}
//getters and setters
public int getCustId() {
return custId;
}
public void setCustId(int custId) {
this.custId = custId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNextNum() {
return nextNum;
}
public void setNextNum(int nextNum) {
this.nextNum = nextNum;
}
public boolean isGoldCardMember()
{
return goldDude;
}
public void setGoldCardMember(boolean goldCardMember) {
this.goldDude = goldCardMember;
}
}
import java.text.NumberFormat;
public class Rental {
// the Rental class has four fields
private Customer cust;
private Auto auto;
private int numDays;
private double rentalCost;
private char discount; // N = none G = gold D = days B = both
// all cars rent for $15.00 per day
final private double COST_PER_DAY = 15.00;
// TO DO!!write an empty and a full constructor
public Rental(){}
public Rental(Customer c, Auto a, int d){
cust = c;
auto = a;
numDays = d;
setRentalCost();
}
// toString method
//remember that each class should print out its own fields
// so we let the Auto and Customer class print out theirs
// this class only prints out the number of days field
@Override
public String toString()
{
NumberFormat nf = NumberFormat.getCurrencyInstance();
String string;
string = cust.toString() + " rented " ;
string = string + auto.toString() + " for " + numDays + " days.";
string = string + " The cost was " + nf.format(rentalCost) + " ";
switch (discount) {
case 'B':
string = string + "This person was both a gold card memeber and rented over six days and received a 25% discount";
break;
case 'G':
string = string + "This person was a gold card member and received a 10% discount";
break;
case 'D':
string = string + "This person rented over six days and received a 15% discount";
break;
case 'N':
string = string + "This person did not qualify for a discount";
}
return string;
}
// TO DO!!!the setRentalCost is where the cost is set
public void setRentalCost()
{
final double GCM_DISCOUNT = (.10);
final double DAYS_DISCOUNT = (.15);
final double GCM_DAYS_DISCOUNT = (.25);
rentalCost = numDays*COST_PER_DAY;
if(numDays>6 && cust.isGoldCardMember()){
rentalCost = rentalCost -(rentalCost*GCM_DAYS_DISCOUNT);
discount = 'B';
}
else if(numDays>6){
rentalCost = rentalCost-(rentalCost*DAYS_DISCOUNT);
discount ='D';
}
else if(cust.isGoldCardMember()){
rentalCost = rentalCost -(rentalCost*GCM_DISCOUNT);
discount = 'G';
}
else discount = 'N';
}
public void setAuto(Auto auto) {
this.auto = auto;
}
public Customer getCust() {
return cust;
}
public void setCust(Customer cust) {
this.cust = cust;
}
public int getNumDays() {
return numDays;
}
public void setNumDays(int numDays) {
this.numDays = numDays;
}
public double getRentalCost() {
return rentalCost;
}
// give them a 15% discount if they rent over 6 days. Also Gold card members get an
//extra 10% off the original cost regardless of the number of days
// note next line is just a place holder. Also set the discount code
}
// generate getters and setters
import java.util.*;
public class WreckDriver {
public static void main(String[] args)
{
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
ArrayList c = new ArrayList();
ArrayList a = new ArrayList();
ArrayList r = new ArrayList();
loadNewData(a, c);
boolean more = true;
while (more)
{
System.out.println("Customers:");
for (int i=0;i //customer list displayed and input requested from user// System.out.println(" Which customer?"); int cust =sc.nextInt()-1; //customer record checked for gold card member status// if(c.get(cust).isGoldCardMember()) System.out.println("This customer is a gold card member so we will treat him well! "); else System.out.println("This customer is not a gold card member "); System.out.println("The following cars are available to rent..."); showCars(a); //menu of cars available to rent is displayed and user is prompted for choice// System.out.println(" Which auto?"); int car = sc.nextInt()-1; System.out.println("How many days do you wish to have this beautiful vehicle?"); int days = sc.nextInt(); //rental length determined// Rental rent = new Rental(c.get(cust),a.get(car), days); r.add(rent); System.out.println(rent.toString()); //new rental record added to ArrayList 'r'// //user prompt - add more rentals, or continue on// boolean inputIsInvalid = true; while (inputIsInvalid) { System.out.println("more rentals? (yes/no): "); String choice = sc.next(); if ("yes".equalsIgnoreCase(choice))inputIsInvalid = false; else if ("no".equalsIgnoreCase(choice)){inputIsInvalid = false; more = false;} else System.err.print("Error: Only valid answers are 'yes' or 'no'."); } //if 'no' , rental summaries are printed // } System.out.println(" Rental Summary:"); printRentals(r); } public static void loadNewData(ArrayList a, ArrayList c) { a.add(new Auto(2009,"Ford" , "Mustang","ABC123", 1256.54)); a.add(new Auto(2010,"Chevy","Camero","QWI459", 33.98)); a.add(new Auto(1970,"Pink","Cadillac","950AKH", 212874.51)); a.add(new Auto(2007,"Lotus","Elise MkII","1A2D3F", 12859.90)); c.add(new Customer( "Brett Farve",false)); c.add(new Customer( "Bruce Springsteen",true)); c.add(new Customer( "Mickey Mouse", true)); c.add(new Customer( "Peyton Manning", true)); c.add(new Customer( "Donald Duck", true)); } //Prints the cars that are available for rent public static void showCars(ArrayList a) { for (int i=0;i System.out.println(i+1 + " " + a.get(i).toString()); } // prints all the rentals that have been made public static void printRentals(ArrayList r) { for (int i=0;i System.out.println(r.get(i).toString()); } } Alter the program so that a car is removed from the list after it is rented so two people cannot rent the same one.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started