1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Olin [163]
4 years ago
12

Write a Java program to create a class called Cars. The class should include three instance variables: makes (type: String), mod

els (type: String), and years (type: int); and two methods: a constructor() to initialize three variables and a show() to display the information of a car. Write a class called TestCars to test the class Cars. This class should be able to read the makes, models, and years of three cars from screen input, create three-car objects using the constructor() and display each car's make, model, and years using the show(). (5pts)
Computers and Technology
1 answer:
Fiesta28 [93]4 years ago
5 0

Answer:

Explanation:

This code was written in Java. It creates the Cars class with the requested variables and methods. It also creates the TestCars class which asks the user for the necessary inputs and then creates three Cars objects and passes the input values to the constructors. Finally, it uses the show() method on each object to call the information. A test has been created and the output can be seen in the attached image below.

import java.util.Scanner;

class TestCars{

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.print("Enter Car Make: ");

       String make1 = in.next();

       System.out.print("Enter Car Model: ");

       String model1 = in.next();

       System.out.print("Enter Car Year: ");

       int year1 = in.nextInt();

       System.out.print("Enter Car Make: ");

       String make2 = in.next();

       System.out.print("Enter Car Model: ");

       String model2 = in.next();

       System.out.print("Enter Car Year: ");

       int year2 = in.nextInt();

       System.out.print("Enter Car Make: ");

       String make3 = in.next();

       System.out.print("Enter Car Model: ");

       String model3 = in.next();

       System.out.print("Enter Car Year: ");

       int year3 = in.nextInt();

       Cars car1 = new Cars(make1, model1, year1);

       Cars car2 = new Cars(make2, model2, year2);

       Cars car3 = new Cars(make3, model3, year3);

       car1.show();

       car2.show();

       car3.show();

   }

}

class Cars {

   String makes, models;

   int years;

   public Cars(String makes, String models, int years) {

       this.makes = makes;

       this.models = models;

       this.years = years;

   }

   public void show() {

       System.out.println("Car's make: " + this.makes);

       System.out.println("Car's model: " + this.models);

       System.out.println("Car's year: " + this.years);

   }

}

You might be interested in
What causes the natural event called El Niño? In a short paragraph, describe El Niño and the effects it has on Latin America.
iren2701 [21]

El Niño is a pattern in climate change occurring as the result of accelerated temperatures in the tropical-eastern regions of the Pacific Ocean for a shorter or extended period of time. This phenomenon affects areas of the western and southern parts of America impacting all natural resources including ocean life. In the past, El Niño has also caused serious disease outbreaks among the local population.

Explanation:

El Niño keeps the western pacific coast very warm and dry leading to drought.

Responsible for extremely wet monsoons, may lead to severe flooding along the Caribbean coast.

The opposite effect is known as “La Niña” that has adverse positive effects on the ecosystem, bringing in nutrient-rich cooler-water currents.

3 0
3 years ago
Is phone data used when connected to wifi
finlep [7]
I do not think so, no.
7 0
4 years ago
Choose the answer that best completes the statement.
Anestetic [448]
1. A - everything starts there
2. D - always
3. C - true
4 0
3 years ago
Read 2 more answers
An outdoor products company wants to test a new website design where customers can get information about their favorite outdoor
ExtremeBDS [4]

Answer:

Option (A) is the right answer for factors.

Option (B) is the right answer for factor levels.

Explanation:

As per the scenario, the company wants to see the effect of their new website design on their customers, for which the factor of time spent on the new website is right because it gives the company to acknowledge the data of time spent by a customer on the new website.

To reach the result of the factor, we have to work on the factor level, in which we will compare the time spent on the old website and the new website because it gives the company an idea of customers preferring which website design.

8 0
3 years ago
Mary’s computer is running slow and will not load programs or videos. She has tried restarting her computer yet it is still not
luda_lava [24]
She shall not reset her computer because she will have to load every thing again
8 0
4 years ago
Other questions:
  • You have an interface on a router with the IP address of 192.168.192.10 /29. What is the broadcast address the hosts will use on
    15·1 answer
  • Which of the following solutions enables simultaneous digital transmission of voice, video, data, and other network services ove
    7·1 answer
  • While saving her word-processed academic documents, Ashley includes the subject, title, and the author's name in the properties.
    7·1 answer
  • Pop3 allows users to fetch and download e-mails from a remote mailbox. does this mean that the internal format of the mailboxes
    14·1 answer
  • Which concept often comes in conflict with privacy rights?
    14·1 answer
  • Write the code for the following problem.
    9·1 answer
  • 1. Who was able to complete the puzzle the fastest in Trial 1?
    15·1 answer
  • A message can be...........<br>differently by different people.​
    8·1 answer
  • What are the two main parts to a VR experience.
    12·1 answer
  • Match the correct answers with the statements.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!