Write a program for a dealership that displays information a

Write a program for a dealership that displays information and cost about a particular car model. Allow the program to take in the car model as user-input, as well as the initial cost. It will then add a 3.6% sales tax to the total price. We will also assume that the customer has a membership with the dealership, which means they will also receive a 15% discount, calculate in after tax. You must display these items at the end: Car Model Initial Cost Sales Tax Discount Final Price The salesman is also interested in how much he receives as commission, which is 10% of the final cost. Calculate this and display it for him.

Solution


/**
* The java program that prompts user to enter
* car model, cost and then calculates sales tax,
* discount and final price and print to console.
* */
//CarDealership.java
import java.util.Scanner;
public class CarDealership
{
   public static void main(String[] args)
   {
       //Instnace of Scanner class
       Scanner scanner=new Scanner(System.in);
       //declare variables
       String carModel;
       double cost;
       double salesTaxRate=0.035;
       double salesTax=0;
       double discountRate=0.15;
       double discount=0;
       double finalPrice=0;
      
       System.out.println(\"Enter car model >>>\");
       //prompt for car model
       carModel=scanner.nextLine();
       System.out.println(\"Enter car cost >>>\");
       //prompt for cost
       cost=Double.parseDouble(scanner.nextLine());
      
      
       //calculate sales tax
       salesTax=cost*salesTaxRate;
      
       //calculate final price
       finalPrice=cost+salesTax;
      
       //calculate discount
       discount=finalPrice*discountRate;
      
       //calculat final price
       finalPrice=finalPrice-discount;
      
      
       //print to cossole
       System.out.println(\"----->Car Details<-----\");
       System.out.println(\"Car Model : \"+carModel);
       System.out.println(\"Initial Cost : $\"+cost);
       System.out.println(\"Sales Tax :$\"+salesTax);
       System.out.println(\"Discount : $\"+discount);
       System.out.println(\"Final Price :$\"+finalPrice);
          
   }   //end of main method
}//end of class


------------------------------------------------------------------------------------

Sample Output:

Enter car model >>>
SUV
Enter car cost >>>
500000
----->Car Details<-----
Car Model : SUV
Initial Cost : $500000.0
Sales Tax :$17500.0
Discount : $77625.0
Final Price :$439875.0

 Write a program for a dealership that displays information and cost about a particular car model. Allow the program to take in the car model as user-input, as
 Write a program for a dealership that displays information and cost about a particular car model. Allow the program to take in the car model as user-input, as

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site