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
sdas [7]
3 years ago
13

Write a class named Car that has the following fields:

Computers and Technology
1 answer:
harkovskaia [24]3 years ago
8 0

Answer:

The Solution in Java programming language is provided in the explanation section.

Please observe comments that further explains each step

Explanation:

import java.util.Scanner;

//This is the CarTest Class

public class num1 {

   //The main Method in the Test Class

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       //Receiving Users inputs

       System.out.print("Enter the car's year model: ");

       int yearModel = in.nextInt();

       System.out.print("Enter the car's make: ");

       String make = in.next();

       System.out.print("Enter the car's speed: ");

       int speed = in.nextInt();

       Car newCar = new Car(yearModel,make, speed);

       //Printing Cars Current Status

       System.out.println("Current status of the car:");

       System.out.println("Year Model: "+newCar.getYearModel());

       System.out.println("Make: "+newCar.getMake());

       System.out.println("Speed: "+newCar.getSpeed());

       //Calling the accelerate Method

       for(int i=1; i<6; i++){

           int newSpeed = newCar.getSpeed();

           newCar.setSpeed(newSpeed);

           newCar.accelerate();

           System.out.println("Accelerating...");

           System.out.println("Now the Speed is "+newCar.getSpeed());

       }

       //Calling the Breaking Method

       for(int i=1; i<6; i++){

           int newSpeed = newCar.getSpeed();

           newCar.setSpeed(newSpeed);

           newCar.breaking();

           System.out.println("Breaking...");

           System.out.println("Now the Speed is "+newCar.getSpeed());

       }

   }

}

//The Car CLass begins here

class Car{

   private int yearModel;

   private  String make;

   private int speed;

   // Cnstructors

   public Car(int yearModel, String make,int speed ){

       this.speed = speed;

       this.make = make;

       this.yearModel = yearModel;

   }

   public Car(){

       this.yearModel =0;

       this.speed = 0;

       this.make = "";

   }

   //Accessor Methods

   public int getYearModel() {

       return yearModel;

   }

   public String getMake() {

       return make;

   }

   public int getSpeed() {

       return speed;

   }

   //Mutators

   public void setYearModel(int yearModel) {

       this.yearModel = yearModel;

   }

   public void setMake(String make) {

       this.make = make;

   }

   public void setSpeed(int speed) {

       this.speed = speed;

   }

   //Method Accelerate

   public void accelerate(){

        this.speed = this.speed + 5;

   }

   //Method Break

   public int breaking(){

       return this.speed = this.speed - 5;

   }

}

You might be interested in
Consumers who wish to make a purchase from other consumer on ebay need tl
il63 [147K]

Answer:

Bid on item

Explanation:

Consumers who wish to make a purchase from other consumer on ebay need to first of all bid on the item. This is done by specifying the price in which the purchase should be made.

When this is done, the seller contacts the buyer if he/she’s okay with the price of the goods and services and other formalities are discussed.

8 0
3 years ago
Explain 3 ways you can be an upstander when seeing cyberbullying.
Bess [88]

Answer:

Assuming an upstander is someone that opposes cyberbullying:

(1) Call them out

(2) Report the behavior to proper moderation authority

(3) Tell the person to block messages from the cyberbully

I don't really know what else you want from this.

Cheers.

3 0
4 years ago
Read 2 more answers
Please help me very important
3241004551 [841]

Answer:

C, Or D.

Explanation:

<em>Because A speed enhancing hard drive Can store any type of quick file if you just click on it will load fast. Same thing goes for a hard drive but you have to transfer the file</em>

4 0
3 years ago
Modern ancestor of the typewriter
Rashid [163]
I would think Microsoft Word would be the answer. It does everything a typewriter can.
4 0
3 years ago
Read 2 more answers
What is true about music from the Romantic period?
avanturin [10]
The answer to the given question above is the third option: <span>It was longer and less constrained than the music of the Classical period. The Romantic Period in music actually has more freedom in design and form. During this period, music were even more artistic and intellectual as well. Romantic Period occurred the late 18th century until early 19th century.</span>
8 0
3 years ago
Read 2 more answers
Other questions:
  • A network engineer arrives at work and discovers that many users are having problems when attempting to connect to the company n
    9·2 answers
  • Which payment type is best if you are trying to sick to a budget?
    15·1 answer
  • When powering off your computer is best down using?
    8·2 answers
  • What was the major sign that lead Professor Shiller to predict the crash of the housing market​
    6·1 answer
  • 1. provide at least 3 properties and 3 methods of the object computer.
    8·1 answer
  • What are the uses of plotters​
    7·2 answers
  • The cutting tool that has a zig zag edge is called a?
    9·1 answer
  • Output each floating-point value with two digits after the decimal point, which can be achieved by executing cout &lt;&lt; fixed
    7·1 answer
  • The first real computer was an abacus?
    13·1 answer
  • The rectangle shape in flowchart is used for
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!