Create a class called Car that includes three instance variables—a model (type
String), a year (type String), and a price (double). Provide a constructor that initializes the three
instance variables. Provide a set and a get method for each instance variable. If the price is not positive,
do not set its value. Write a test application named CarApplication that demonstrates class Car’s capabilities. Create two Car objects and display each object’s price. Then apply a 5% discount on the
price of the first car and a 7% discount on the price of the second. Display each Car’s price again.

Answers

Answer 1

Answer:

Here is the implementation of the Car class:

class Car {

 private String model;

 private String year;

 private double price;

 public Car(String model, String year, double price) {

   this.model = model;

   this.year = year;

   if (price > 0) {

     this.price = price;

   }

 }

 public String getModel() {

   return model;

 }

 public void setModel(String model) {

   this.model = model;

 }

 public String getYear() {

   return year;

 }

 public void setYear(String year) {

   this.year = year;

 }

 public double getPrice() {

   return price;

 }

 public void setPrice(double price) {

   if (price > 0) {

     this.price = price;

   }

 }

}

Here is the test application that demonstrates the capabilities of the Car class:

class CarApplication {

 public static void main(String[] args) {

   Car car1 = new Car("Toyota", "2020", 20000);

   Car car2 = new Car("Honda", "2019", 25000);

   System.out.println("Original price of car1: $" + car1.getPrice());

   System.out.println("Original price of car2: $" + car2.getPrice());

   car1.setPrice(car1.getPrice() * 0.95);

   car2.setPrice(car2.getPrice() * 0.93);

   System.out.println("Discounted price of car1: $" + car1.getPrice());

   System.out.println("Discounted price of car2: $" + car2.getPrice());

 }

}


Related Questions

Select the word that best completes the sentence. Osha's standards require your employer to ensure that lighting, equipment, motors, machines, appliances, switches, controls and enclosures are constructed and installed to _____________ electrical dangers.

Answers

The word that best completes the sentence. is "MInimize"

Thus, Osha's standards require your employer to ensure that lighting, equipment, motors, machines, appliances, switches, controls, and enclosures are constructed and installed to MInimize electrical dangers.

What are OSHA Standards?

OSHA standards are guidelines that specify how companies must safeguard their employees from dangers. OSHA rules are divided into four categories: general industry, building, maritime, and agriculture. (The General Industry set relates to the greatest number of people and workplaces.)

OSHA standards include requirements to provide protective clothing, prevent tunneling cave-ins, reduce exposure to some communicable diseases, guarantee the safety of workers entering confined spaces, prevent exposure to potentially harmful substances such as asbestos and lead, and install machine guards, among other things.

Learn more about OSHA:
https://brainly.com/question/29345131?
#SPJ1

Type MC cable provides an effective ground-fault current path and is recognized by the NEC as an equipment grounding conductor when _____.

Answers

In accordance with 250.118(1), A MC cable includes an insulated or uninsulated equipment grounding conductor.

When does MC cable is recognized by the NEC as an equipment grounding conductor?

Type MC cable that provides an efficient ground-fault current path in compliance with one or more of the following is :

1. In accordance with 250.118(1).2. The interlocked metal tape-type MC cable's combined metallic sheath and uninsulated equipment grounding/bonding conductor that is listed and identified as an equipment.3. The smooth or corrugated tube-type MC cable's metallic sheath, or the combined metallic sheath and equipment grounding conductors, that is listed and identified as an equipment grounding conductor.

To know more about MC cable, visit: https://brainly.com/question/14934410

#SPJ4

Other Questions
Which relation is a function? Please help I have less than 9 minutes many psychologists believe that our sense of free will is mostly an illusion and that our behavior is mostly determined by external forces. who is the scientist who takes the most extreme version of this position and how does he explain why we do what we do, if not by our own conscious choice? Cytotoxic T-lymphocytes produce:- Class II MHCs- Self proteins- Antibodies, which make holes in cell membrane of infected cells- Perforin, which makes holes in cell membrane of infected cells what was the flashback in page 59 on HATCHET? why is the blood-testis barrier , formed by systentocyte cells, important? group of answer choices to prevent immune cells to attack sperm cells. because immature sperm cells lose their motility when they encounter any blood component actually, the blood-testis barrier has no function. because some blood contents are toxic to the spermatozoa WILL GIVE BRAINLIEST AND 20 POINTS!!!a team in your company is struggling to meet the performance level that is expected if them.bHow should we best implement goal-setting in a team context?A. set difficult and specific goals unique to each team memberB. create a common goal for the whole teamC. establish a goal by telling the team to do the best they can doD. have the team establish their own difficult goals can you solve please Ernie Brody had $3,620 on deposit at Savings Bank on July 1. The money earns interest at a rate of 6.5% compounded quarterly untilApril 1 of the flllowing year. (1 point) 5 dice of different colors are rolled, and the number coming up on each die is recorded. how many different outcomes are possible? your answer is : PLEASE HELP Explain how you can identify the opposite and adjacent sides of a right triangle and explain how these can change in any given triangle. Use a diagram to support your explanation. what is the correct order in which inhaled air sequentially moves through the structures of the respiratory passageways starting from the mouth ? youve read in chapter 5 that common knowledge does not have to be cited in your scholarly work. for each of the following examples, indicate whether its common knowledge or needs to be cited. 20 point question! Please help! Which of the following questions should you consider when preparing to communicate with customers or colleagues?a. In what ways can I make my thoughts less transparent?b. Is trustworthiness or credibility key to the way I work?c. How can I maintain dominance?d. How can I best hide my weaknesses? On a recent survey, students were asked if they like to fly and if they can drive. The partial results are given in the relative frequency table.Complete the relative frequency table, showing all necessary calculations. HELP PLSThe half-life of sodium-25 is 1.0 minute. Starting with 1 kg of this isotope, how much will remain after half an hour? Determine the number of solutions for the equation below.-7x + 7 + 12x = 5x + 7A. infinite solutionsB. Two solutionsC. One solutionD. no solution What is the name of the scientist that developed the classification system we use today?. What was the impact of glaciation on the netherlands? question 22 options: a. provided mucklands to grow crops b. provided a perpetual source of drinking water c. provided a natural drainage system for the region d. provided hydro-power resources