In: Computer Science
Create an application named Rusty2 that asks the user for the dealer cost of a car, and the cleaning cost, and then displays the retail cost. Your application should simply send the dealer cost and cleaning cost to the getRetailPrice method in the Dealership class to obtain the retail cost.
here below is the dealership class code amd meed to create rusty2 code
import java.util.Calendar;
public class Dealership {
// public static final class variables
public static final int YEAR_STARTED = 1995;
public static final String COMPANY_NAME = "The Rusty Lemon";
public static final String COMPANY_URL =
"www.TheRustyLemon.com";
public static final String COMPANY_ADDRESS = "123 Rustbelt Road,
Somewhere, SomeState, 12345";
public static final String COMPANY_SLOGAN = "Many parts of our cars
run great!";
public static final double STANDARD_MARKUP = 0.50;
public static final String COMPANY_EMAIL =
"[email protected]";
// public static methods
public static String getCompanyBanner() {
return COMPANY_NAME + "\n(Selling rusty lemons since "
+ YEAR_STARTED + ")\n" + COMPANY_ADDRESS + "\n"
+ COMPANY_URL + "\n" + COMPANY_SLOGAN + "\n";
}
public static double getRetailPrice(double dealerCost, double cleaningCost) {
double markup = dealerCost * STANDARD_MARKUP;
return dealerCost + cleaningCost + markup;
}
public static int getYearsInBusiness()
{
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
int yearsInBusiness = currentYear - YEAR_STARTED;
return yearsInBusiness;
}
}
Solution:
Rusty2.java:
import java.util.*;
public class Rusty2 {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
//Asking user to inout the value of
Dealer cost
System.out.println("Enter Dealer
cost: ");
double dealerCost =
sc.nextDouble();
//Asking the user to input cleaning
cost
System.out.println("Enter Cleaning
cost: ");
double cleaningCost =
sc.nextDouble();
//creating a new variable
retailCost
double retailCost;
//creating a new dealership
object
Dealership dealership = new
Dealership();
//Now we are calling the
fetReatilprice method of dealership class using the dealership
object and storing the return value in retailCost
retailCost =
dealership.getRetailPrice(dealerCost,cleaningCost);
//Printing the retailCost
System.out.println("Retail cost is
" + retailCost);
return;
}
}
Output: