Question

In: Computer Science

An object Car can be described by the manufacturer (Honda, Toyota and Nissan), its price, and...

  • An object Car can be described by the manufacturer (Honda, Toyota and Nissan), its price, and its quantity. These attributes are not accessible by other classes. The class contains a parameterized constructor that sets the attributes using mutator methods. The accessibility of the mutator methods are local to the class. It also has accessor methods that return the respective value of the attributes. The accessor method for getManufacturer() will return the code of the car (H, T or N) instead of “Honda”, “Toyota” and “Nissan”.   Include a method calcTotalPrice() that returns the total price of the cars after the discount, and a displayInfo () method that returns the information about the car such as the manufacturer, price for each car, quantity, and total price after the discount.

Your TASK

Part 1

Write the class Car . Save the file as Car.java.

Part 2

Create a client class ClientCar and save as ClientCar.java.

In the client class, do the following: -

You are required to declare 2 different Cars. Get the input for for manufacturer, the quantity and price. Display the information for each car, such as the manufacturer, price for each car, quantity, and total price after the discount.

     Discount: -

Total Price > 300 000 : Discount 20%

Total Price > 50000 – Discount 10%

Solutions

Expert Solution

Code

Car.java


public class Car {
   private String manufacturer;
   private int quantity;
   private double price;
   /**
   * @param manufacturer
   * @param quantity
   * @param price
   */
   public Car(String manufacturer, int quantity, double price) {
       super();
       this.manufacturer = manufacturer;
       this.quantity = quantity;
       this.price = price;
   }
   /**
   * @return the manufacturer
   */
   public String getManufacturer() {
       return manufacturer.charAt(0)+"";
   }
   /**
   * @return the quantity
   */
   public int getQuantity() {
       return quantity;
   }
   /**
   * @return the price
   */
   public double getPrice() {
       return price;
   }
   /**
   * @param manufacturer the manufacturer to set
   */
   private void setManufacturer(String manufacturer) {
       this.manufacturer = manufacturer;
   }
   /**
   * @param quantity the quantity to set
   */
   private void setQuantity(int quantity) {
       this.quantity = quantity;
   }
   /**
   * @param price the price to set
   */
   private void setPrice(double price) {
       this.price = price;
   }
  
   public double calcTotalPrice()
   {
       double totalCost=quantity*price;
       if(totalCost>300000 )
           totalCost-=totalCost*0.2;
       else if(totalCost>50000 )
           totalCost-=totalCost*0.1;
       return totalCost;
   }
  
   public String displayInfo ()
   {
       return "Manufacturer: "+manufacturer+"\nQuantity: "+quantity+"\nPrice: "+price+"\nTotal price: "+calcTotalPrice();
   }
}

CarClient.java

import java.util.Scanner;

public class ClientCar {

   public static void main(String[] args) {
       Scanner scnr=new Scanner(System.in);
       String manu;
       int qnty;
       double price;
       System.out.print("Enter the car manufacturer: ");
       manu=scnr.next();
       System.out.print("Enter the car quantity: ");
       qnty=scnr.nextInt();
       System.out.print("Enter the price: ");
       price=scnr.nextDouble();
       Car car1=new Car(manu, qnty, price);
       System.out.print("Enter the car manufacturer: ");
       manu=scnr.next();
       System.out.print("Enter the car quantity: ");
       qnty=scnr.nextInt();
       System.out.print("Enter the price: ");
       price=scnr.nextDouble();
       Car car2=new Car(manu, qnty, price);
      
       System.out.println(car1.displayInfo());
       System.out.println();
       System.out.println(car1.displayInfo());
       System.out.println();
   }

}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

Based on 2017 sales, the six top-selling compact cars are the Honda Civic, Toyota Corolla, Nissan...
Based on 2017 sales, the six top-selling compact cars are the Honda Civic, Toyota Corolla, Nissan Sentra, Hyundai Elantra, Chevrolet Cruze, and Ford Focus.† The 2017 market shares are: Honda Civic 20%, Toyota Corolla 17%, Nissan Sentra 12%, Hyundai Elantra 10%, Chevrolet Cruze 10%, and Ford Focus 8%, with other small car models making up the remaining 23%. Suppose a sample of 400 compact car sales in a certain large city showed the following number of vehicles sold. Honda Civic...
Polluters C02 emiision per thousands Buick 25 Toyota 15 BMW 20 Honda 15 Nissan 13 Chevy...
Polluters C02 emiision per thousands Buick 25 Toyota 15 BMW 20 Honda 15 Nissan 13 Chevy 28 Cadillac 38 Chart 1a shows 7 major polluters. Each polluter (a)If the government’s Ministry on Environment were planning to set a different tax rate so as to maximize tax revenue in the most efficient way possible, and they asked you for advice on how best to approach the problem, what would you tell them? You must use *appropriate* terms and concepts in your...
Toyota Corp.'s stock price has a variance of returns equal to 0.0335. Honda Corp.'s stock price...
Toyota Corp.'s stock price has a variance of returns equal to 0.0335. Honda Corp.'s stock price has a variance of returns equal to 0.0455. The covariance between Toyota and Honda is 0.0675. What is the standard deviation of a portfolio consisting of 50% Toyota and 50% Honda? *Place your answer in decimal form *please show how to get anwser
A tire manufacturer believes that the tread life of its snow tires can be described by...
A tire manufacturer believes that the tread life of its snow tires can be described by Normal model with a mean of 32,000 miles and a standard deviation of 2500 miles. a). If you buy a set of these tires, would it be reasonable for you to hope that they'll last 40,000 miles? Explain. b). Approximately what fraction of these tires can be expected to last less that 30,000 miles? c). Approximately what fraction of these tires can be expected...
A car manufacturer claims that the miles per gallon (mpg) of all its midsize cars can...
A car manufacturer claims that the miles per gallon (mpg) of all its midsize cars can be modeled with a normal model with N(33, 1.70). What proportion of cars have miles per gallon less than 31.2 [P(x ≤31.2 mpg)]? What proportion of cars will have miles per gallon greater than 36 [P(x ≥36 mpg)]? What proportion of cars will have miles per gallon less than 30[P(x ≤30 mpg)]? What proportion of cars will have miles per gallon between 32 and...
A car manufacturer, Swanson, claims that the mean lifetime of one of its car engines is...
A car manufacturer, Swanson, claims that the mean lifetime of one of its car engines is greater than 220000 miles, which is the mean lifetime of the engine of a competitor. The mean lifetime for a random sample of 23 of the Swanson engines was with mean of 226450 miles with a standard deviation of 11500 miles. Test the Swanson's claim using a significance level of 0.01. What is your conclusion?
And object is undergoing simple harmonic motion along the x-axis. Its position is described as a...
And object is undergoing simple harmonic motion along the x-axis. Its position is described as a function of time by x(t) = 2.7 cos(3.1t – 1.2), where x is in meters, the time, t, is in seconds, and the argument of the cosine is in radians. A) Find the amplitude of the simple harmonic motion, in meters. B) What is the value of the angular frequency, in radians per second? C) Determine the position of the object, in meters, at...
An object is undergoing simple harmonic motion along the x-axis. Its position is described as a...
An object is undergoing simple harmonic motion along the x-axis. Its position is described as a function of time by x(t) = 5.5 cos(6.9t – 1.1), where x is in meters, the time, t, is in seconds, and the argument of the cosine is in radians. Part (a) Find the amplitude of the simple harmonic motion, in meters. 14% Part (b) What is the frequency of the motion, in hertz? 14% Part (c) Determine the position of the object, in...
Toyota wants to know how its compact car compares in average gasoline mileage per gallon to...
Toyota wants to know how its compact car compares in average gasoline mileage per gallon to Ford. 30 drivers are selected to drive the same route twice, once in each brand of car. Test whether Toyota’s mean is statistically lower at the 1% significance level. Toyota Ford n 1= 30 n 2= 30 x ¯ 1= 26.8 x ¯ 2= 31.7 σ 1= 17.6 σ 2= 16.0 What are the appropriate null and alternative hypotheses?
Honda Motor Company is considering offering a $1,900 rebate on its​ minivan, lowering the​ vehicle's price...
Honda Motor Company is considering offering a $1,900 rebate on its​ minivan, lowering the​ vehicle's price from $30,500 to $28,600. The marketing group estimates that this rebate will increase sales over the next year from 40,400 to 55,700 vehicles. Suppose​ Honda's profit margin with the rebate is $5,250 per vehicle. If the change in sales is the only consequence of this​ decision, what are its costs and​ benefits? Is it a good​ idea?​ Hint: View this question in terms of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT