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
Explain the role of ICT in banks​
vladimir1956 [14]

Answer: ICT help banks improve the efficiency and effectiveness of services offered to customers, and enhances business processes, managerial decision making, and workgroup collaborations, which strengthens their competitive positions in rapidly changing and emerging economies.

Explanation: please give branliest I only need one more to make ace

7 0
3 years ago
Select the correct answer. Marie uses a browser to visit a blog. How is the blog uniquely identified? A. web page B. website C.
damaskus [11]

Answer:

I belive the answer is E

Explanation:

8 0
3 years ago
In the context of firewall as a nonbiometric security measure, a _____ is software that acts as an intermediary between two syst
irga5000 [103]

Answer:

Proxy Server                        

Explanation:

  • Proxy server is a server that acts as a mediator between two systems.
  • One system can be your computer and the other can be the server to which you are asking a service, such as requesting a web page.
  • Lets suppose you request a web page from a server and you type a URL of a website to access a web page.
  • This request goes to proxy server which sends this request on your behalf to the target server in order to retrieve that web page.
  • Proxy server makes this request to the target server on the internet by using one of its IP addresses.
  • When the proxy server gets that web page, it will forward that web page to your requesting computer.
  • If you request a specific service such as a website frequently the proxy server saves that website on its cache.
  • So if you request that website again, proxy server will forward it to you from its cache rather than requesting it again from the target server on your behalf resulting in quick response to the user's request.
  • Proxy servers provide users with privacy to access the websites, and they can surf the internet anonymously .
8 0
3 years ago
a.Write a Python function sum_1k(M) that returns the sum푠푠= ∑1푘푘푀푀푘푘=1b.Compute s for M = 3 by hand and write
stealth61 [152]

Answer:

def sum_1k(M):

   s = 0

   for k in range(1, M+1):

       s = s + 1.0/k

   return s

def test_sum_1k():

   expected_value = 1.0+1.0/2+1.0/3

   computed_value = sum_1k(3)

   if expected_value == computed_value:

       print("Test is successful")

   else:

       print("Test is NOT successful")

test_sum_1k()

Explanation:

It seems the hidden part is a summation (sigma) notation that goes from 1 to M with 1/k.

- Inside the <em>sum_1k(M)</em>, iterate from 1 to M and calculate-return the sum of the expression.

- Inside the <em>test_sum_1k(),</em> calculate the <em>expected_value,</em> refers to the value that is calculated by hand and <em>computed_value,</em> refers to the value that is the result of the <em>sum_1k(3). </em>Then, compare the values and print the appropriate message

- Call the <em>test_sum_1k()</em> to see the result

8 0
3 years ago
Jeff wants to print quickly so he presses the Ctrl and the P. Jeff used a _____. macro invoice template shortcut
Allushta [10]
He used a keyboard shortcut.
3 0
4 years ago
Other questions:
  • Consider the binary search tree constructed for the words oenology, phrenology, campanology, ornithology, ichthyology, limnology
    14·1 answer
  • What does input mean in the universal systems model
    14·1 answer
  • How to transfer photos from iphone to iphone?
    14·2 answers
  • Quien invento el primer vehiculo con motor?
    15·2 answers
  • True or False: It is illegal to park in a location that you block or create a hazard for other vehicles.
    11·2 answers
  • What is institutional advertising focused on promoting?
    8·1 answer
  • What is the difference between a technological problem and a technological opportunity? Explain with an example.
    7·2 answers
  • The large program that controls how the CPU communicates with other components is the​
    9·1 answer
  • HI! THIS IS THE PERSON FROM EARLIER WHO HAD PROBLEMS WITH THEIR PASSWORD
    8·1 answer
  • How do I change the keyboard light colors on Alienware 17 R5?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!