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]
3 years ago
14

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

Computers and Technology
1 answer:
meriva3 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
Decrypt this message: P ht uva h zwf
KatRina [158]
Translation: I am a spy
5 0
3 years ago
The algorithm and flowchart
tatuchka [14]

Answer:

Make a IPO chart it will be way easier!

Explanation:

4 0
4 years ago
What is ABC computer?​
mezya [45]

Answer: The Atanasoff–Berry computer was the first automatic electronic digital computer. Limited by the technology of the day, and execution, the device has remained somewhat obscure. The ABC's priority is debated among historians of computer technology, because it was neither programmable, nor Turing-complete.

Explanation:

5 0
3 years ago
etwork behavior analysis system __________ sensors are typically intended for network perimeter use, so they are deployed in clo
jeka94

Answer:

"Inline" is the correct answer.

Explanation:

  • Network behavior analysis (NBA)  or Analysis of network activity seems to be the technique to observe traffic trends that aren't groups or sets throughout the cable network's everyday traffic.
  • Simplest terms, this is the organization's effort to define network anomalies outside pure congested traffic expect a seamless.

So that the above is the correct answer.

6 0
3 years ago
Por favor definir que es un pseudocódigo y que es un diagrama de flujo.
marusya05 [52]

Answer:

que

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • Write a sequence of statements that create a file named "greeting" and write a single line consisting of "Hello, World!" to that
    5·1 answer
  • NEED THIS NOW PLEASE!!!! (I AM NOT JOKING I HAVE TO SUBMIT IN 5 MINUTES)
    13·2 answers
  • In order for Dr. Reynolds to send a CPOE from her office computer system to the computer system at the local hospital, a/an ____
    5·1 answer
  • Which method can help you prevent RSI while using a keyboard?
    14·1 answer
  • program students can get credit for their high school classes as long as they take a specific courses that a college will accept
    13·2 answers
  • What is the sum of each pair of binary integers? (assuming 8-bit register is used)
    5·1 answer
  • Which of the following controls will provide an area in the form for the user to enter a name? a. button b. label c. text box d.
    8·1 answer
  • Shira’s Shoes sold 875,000 pairs of sandals in June, which was 70% of the total number of shoes sold. How many shoes did the com
    14·2 answers
  • In which of the following situations would it be most appropriate to choose lossy compression over lossless compression?
    5·1 answer
  • In your own opinion how comes the surface grinding machine is called a highly accurate machine tool?​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!