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
8090 [49]
4 years ago
14

Write a class named Car that has the following data attributes:

Computers and Technology
1 answer:
meriva4 years ago
7 0

ANSWER

The program in JAVA for the given scenario is as follows.

import java.util.*;

public class Car

{

// variables declaration

   static int _year_model;

   static String _make;

   static int _speed;

   

   public static void _init_( int model, String m )

   {

// variables initialization

       _year_model = model;

       _make = m;

       _speed = 0;

   }

   

   public static void accelerate()

   {

       _speed = _speed + 5;

   }

   

   public static void brake()

   {

       _speed = _speed - 5;

   }

   

   public static int get_speed()

   {

// current value of speed is returned

       return _speed;

   }

   

public static void main(String[] args) {

     

    // object of class created

    Car ob = new Car();

     

    // method called using object of class

    ob._init_(2019, "audi");

     

    ob.accelerate();

 System.out.println("Accelerated speed " + ob.get_speed());

 ob.accelerate();

 System.out.println("Accelerated speed " + ob.get_speed());

 ob.accelerate();

 System.out.println("Accelerated speed " + ob.get_speed());

 ob.accelerate();

 System.out.println("Accelerated speed " + ob.get_speed());

 ob.accelerate();

 System.out.println("Accelerated speed " + ob.get_speed());

 

 System.out.println();

 

 ob.brake();

 System.out.println("Speed after brake " + ob.get_speed());

 ob.brake();

 System.out.println("Speed after brake " + ob.get_speed());

 ob.brake();

 System.out.println("Speed after brake " + ob.get_speed());

 ob.brake();

 System.out.println("Speed after brake " + ob.get_speed());

 ob.brake();

 System.out.println("Speed after brake " + ob.get_speed());

 

}

}

OUTPUT

Accelerated speed 5

Accelerated speed 10

Accelerated speed 15

Accelerated speed 20

Accelerated speed 25

Speed after brake 20

Speed after brake 15

Speed after brake 10

Speed after brake 5

Speed after brake 0

EXPLANATION

1. Variables are declared with String and integer datatypes.

2. _init_() initializes all the variables. This method is also called inside main() using object of Car class in order to initialize the variable speed to 0.

3. Inside main(), object of Car class created.

Car ob = new Car();

4. All the methods are called using object of the class.

ob._init_(2019, "audi");

ob.accelerate();

ob.brake();

5. All the variables are declared as static.

6. All the methods are declared as static since main() method is static inside which all other methods are called.

7. New line is included to improve readability of the output.

You might be interested in
Under what driving conditions will 2019 Nissan LEAF’s available Rear Cross Traffic Alert (RCTA) warn the driver if a vehicle is
Dmitriy789 [7]

Answer:

When the driver is <em>reversing the car</em>

Explanation:

The Rear Cross Traffic Alert (RCTA) is Nissan's <em>risk  of collision detector</em> that warns drivers if one or more cars are approaching the rear of your car when backing up from a parking space.  

Sensors around the back of the vehicle identify vehicles drawing nearer from the either way. A notice tone and glimmering light will appear and  alert the driver to stop.  

5 0
3 years ago
To have a set of command
GalinKa [24]

Every program that interacts with people responds to a specific set of commands. The set of commands and the syntax for entering them is called the user interface and varies from one program to another. The DOS operating system makes a distinction between internal and external commands.

3 0
3 years ago
PLZ ANSWER I WILL GIVE BRAINLIEST
scoray [572]

Answer:

The correct answer is A, spreadsheets. Spreadsheet programs are similar to and include Excel, with grids of cells for organizing numerical data

7 0
3 years ago
Read 2 more answers
What is my mistake on this code? (Python)
UNO [17]

Answer:

Explanation:

bakugo;sup shoto i didnt know you go on here too

the coding has no problems just go and get deki kaminary

4 0
3 years ago
NullPointerException and ArithmeticException are both derived from which class?
irina1246 [14]

Answer: c) Run-time Exception

Explanation: Runtime Exception is the exception that works in the JVM(Java Virtual Machine) as a super-class. It can also act during the general working of the JVM and are not checked by any resources. The exception that are followed from the Runtime exception is Arithmetic exception and  Null pointer exception as the subclass. Therefore ,the correct option is option(c).

3 0
4 years ago
Other questions:
  • What is created for each user the first time the user logs onto windows?
    7·1 answer
  • While performing maintenance work on the components of a computer, you feel a small electric shock. Before you began working, yo
    5·1 answer
  • Build a state diagram for the “book” based upon the following information of the library.
    6·1 answer
  • While working a night job at a call center, Eric creates an app called EatOut, which can be used to place orders at restaurants,
    14·1 answer
  • When communicating with a server on another subnet, which of the following settings is used to determine which direction it need
    6·1 answer
  • The ____ of a variable is the location in memory where it’s value is stored. A. Value B. Address C. Data type D. Number
    8·1 answer
  • Labor-augmenting technology causes which of the following?(i) The marginal productivity of labor increases.(ii) The marginal pro
    7·1 answer
  • Doug grew up on a large farm in southwest Wisconsin. As a college graduation gift, Doug’s father gave him several hundred acres
    6·1 answer
  • How to save an edited document.​
    6·1 answer
  • A programmer is creating an algorithm that will be used to turn on the motor to open the gate in a parking garage. The specifica
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!