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
On five lane roadways, the center lane is designated for __________ and is used by vehicles traveling in both directions.
Alla [95]
Answer : The center lane is designated for left turns

Explanation: 
This lane is used so that drivers would pull into in order to turn left when a clear merge is available. Its main purpose is not to cause traffic jam while waiting for the chance to turn left. It is illegal to use this lane for any other purposes
5 0
4 years ago
Core to resource management system is the _________that coordinates the server hardware.
vichka [17]
Hehdhdjdjddjdjid iridium chi jo j o j o j o j
5 0
3 years ago
Given the following code: PreparedStatement ps = connection.prepareStatement("select firstName, mi, lastName from Student where
katen-ka-za [31]

Answer:

In this question, the code will be given a run-time error.

Explanation:

In java programming, the database code will give a run-time error because cursor in the resultSet that is the object of the resultSet class not point any rows in the table and we must use the resultSet.next() function. This function passes the cursor value to the first row in resultSet class object and this function helps to pass the value in the cursor for the next row in the resultSet class object.

5 0
3 years ago
You are describing the boot process to a friend and get to the step where the device loads the operating files into RAM, includi
EastWind [94]

I would say, "not those kinds of kernels, when I say kernel, I mean the core of your computers operating system. It controls all of the system components and tell specific parts of the computer to do certain things." or in more compact terms, "think of the kernel as the brain of the computer, telling each system component what to do."

5 0
3 years ago
What is the purpose of copyfitting?
stiv31 [10]

Answer:

ms word can help you to writer and print

ur document and make u more attractive

Explanation:

a

3 0
3 years ago
Other questions:
  • A software program that enables users to find and display information stored as html pages on the internet is a(n) ____.
    5·1 answer
  • Identify the parts used in an electric circuit- Tiles
    9·2 answers
  • We say that a sequence of numbers is a palindrome if it is read the same backward or forward. For example, the sequence: 6, 15,
    11·1 answer
  • You are developing open-source software based on existing source code developed by someone else. What is the term for the piece
    9·1 answer
  • You cannot legally install macOS on a PC that originally came with Windows<br> True or false
    13·2 answers
  • Which of the following statements is true?
    8·2 answers
  • What function will delete an element from the end of a deque. On Edge
    13·1 answer
  • What is the iterative procedure of recursive and nonrecursive?
    10·1 answer
  • What is Error Code: 232011
    11·2 answers
  • Which types of file formats are the best choice for files that may need to be edited later?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!