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
iogann1982 [59]
3 years ago
5

Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per ga

llon, and speed. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do not allow the miles per gallon to be less than 10 or more than 60; if it is, set the miles per gallon to 0. Car speed should be initialized as 0. Include a constructor that accepts arguments for each field value and uses the set methods to assign the values. Also, write two methods, Accelerate () and Brake (). Whenever Accelerate () is called, increase the speed by 5, and whenever Brake () is called, decrease the speed by 5. To allow users to specify the speed to increase (or decrease), create two overloading methods for Accelerate () and Brake () that accept a single parameter specifying the increasing (or decreasing) speed. Write an application that declares several Automobile objects and demonstrates that all the methods work correctly. Save the files as Automobile.java and TestAutomobiles.java.
Computers and Technology
1 answer:
aliya0001 [1]3 years ago
4 0

Answer:

public class TestAutomobiles {

   public static void main(String args[]) {

     Automobile obj = new Automobile(1, "Wolkswagen", "Golf", 2007, "GR1GR", 20, 120, "Grey");

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

  System.out.println("Current Speed with acceleration 100: " + obj.accelerate(100));

  System.out.println("Current Speed after using brake : " + obj.brake());

   }

}

class Automobile {

    private int idNumber, year, milesPerGallon, speed = 0;

    private String model, vinNumber, make, color;

   

    public void setIdNumber(int idNumber){

       if (idNumber >= 0 && idNumber <= 9999)

           this.idNumber = idNumber;

       else this.idNumber = 0;

    }

    public void setModel(String model){

        this.model = model;

    }

    public void setYear(int year){

       if (year >= 2000 && year <= 2017)

           this.idNumber = idNumber;

       else this.year = 0;

    }

    public void setVinNumber(String vinNumber){

        this.vinNumber = vinNumber;

    }

    public void setMilesPerGalon(int milesPerGallon){

       if (milesPerGallon >= 10 && year <= 60)

           this.milesPerGallon = milesPerGallon;

       else this.milesPerGallon = 0;

    }

    public void setSpeed(int speed){

        this.speed = speed;

    }

    public void setMake(String make){

        this.make = make;

    }

    public void setColor(String color){

        this.color = color;

    }

    public int getIdNumber(){return idNumber;}

    public String getModel(){return model;}

    public int getYear(){return year;}

    public String getVinNumber(){return vinNumber;}

    public int getMilesPerGallon(){return milesPerGallon;}

    public int getSpeed(){return speed;}

    public String getMake(){return make;}

    public String getColor(){return color;}

   

   public int accelerate() {

       setSpeed(speed + 5);

       return speed;

   }

   public int brake() {

       setSpeed(speed - 5);

       return speed;

   }

   public int accelerate(int s) {

       setSpeed(speed + s);

       return speed;

   }

   public int brake(int s) {

       setSpeed(speed - s);

       return speed;

   }

   

    public Automobile(int idNumber, String make, String model, int year, String vinNumber, int milesPerGallon, int speed, String color){

       setIdNumber(idNumber);

       setModel(model);

       setYear(year);

       setVinNumber(vinNumber);

       setMilesPerGalon(milesPerGallon);

       setSpeed(speed);

       setMake(make);

       setColor(color);

    }

}

Explanation:

Required <em>variables</em> are declared as private members.

Their <em>setters</em> and <em>getter</em> are created.

Two <em>accelearate</em> and two <em>break</em> methods are created.

One <em>constructor</em> taking all variables as parameter is created.

In the main, I tested a few functions to check if they work properly.

You might be interested in
Write a statement to declare a variable x with data type int and initialise with the value 10​
nexus9112 [7]

Answer:

int x = 10;

Explanation:

This would work in many languages (C/C++/C#/Java).

6 0
2 years ago
What is the way of retrieving information from the Internet?
TEA [102]
We have to search the desired topic on the search box in the homepage
4 0
3 years ago
Read 2 more answers
This exspansion slot essentially replaced PCI and AGP slots
MrRa [10]
PCI and AGP slots have been replaced with PCI-E slot (PCI-Express). There are different types of PCI-E buses:

PCI Express 1x (250 [500] * MB/s)
PCI Express 2x (500 [1000] * MB/s)
PCI Express 4x (1000 [2000] * MB/s)
PCI Express 8x (2000 [4000] * MB/s)
PCI Express 16x (4000 [8000] * MB/s)
<span>PCI Express 32x (8000 [16000] * MB/s)

I hope that's what you meant :)</span>
4 0
3 years ago
What is BINARY it is making get confused
enot [183]
It is a number that is expressed in the binary numerical system
6 0
3 years ago
Nadeen runs a website on vegan lifestyle. She wants to spread the word and make more people visit her site to read her recipes a
pashok25 [27]

What Nadeen needs to do to get people to engage with her web site is to regularly post new content and regularly respond to user comments and questions (options A and C).

<h3>What should Nadeen do to increase visits to her website?</h3>

Currently, social networks and pages have become tools to share information and create a community of people around a topic.

From this trend, many people have developed their own web pages to share their knowledge and experience with other people so that knowledge becomes public and help those who do not have as much knowledge.

However, for a page to have high interactions and visits from the public, the owner of the page must ensure that they comply with some recommendations that will increase the traffic of their page, such as:

  • Post frequently: This is because people are constantly looking for information and like to be up to date with the latest.
  • Respond to user comments and questions: This creates a link between the page owner and their visitors that makes them feel comfortable with this page. This also helps the owner create a community where everyone participates by contributing knowledge.

Note: This question is incomplete because the options are missing. Here are the options:

A. She must post new content on her website regularly.

B. She must increase the number of pay-per-click advertisements on her website.

C. She must regularly respond to user comments and questions.

D. She must use a secure payment gateway.

Learn more about vegan in: brainly.com/question/8708517

3 0
2 years ago
Other questions:
  • To keep information beyond reach of unauthorized users, is to keep the information _____. Group of answer choices simple verifia
    7·1 answer
  • Arrange these stages of website design in the order that they follow. developing planning learning designing testing and deliver
    12·1 answer
  • You have been asked to write a program that will ask the user for his or her pizza order and display it. The order will include
    11·1 answer
  • A
    12·1 answer
  • ANSWER THIS CORRECTLY FOR BRAINLIEST
    13·2 answers
  • Edible vaccines, a more controversial approach to vaccine development, have been investigated by scientists. Plants can be genet
    6·1 answer
  • _______ is a form of crime that targets a computer system to acquire information stored on that computer system, to control the
    12·1 answer
  • People using commercially available software are usually asked to read and agree to a(n) _____
    10·1 answer
  • People are starting to type in whole questions rather than specific words, which leads credence to having _____ that have this a
    14·1 answer
  • Which actions are available in the Trust Center? Check all that apply.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!