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
How can you enter Task Manager in Windows? Select 3 options. press Ctrl + Shift + Tab press Ctrl+Alt+Delete and then click Task
Sophie [7]

Answer:

Please find the 3 options below.

Explanation:

To begin with, Task Manager in windows, is a monitor program that provides information or shows application and processes running on a computer. Task manager also provide insights about the general status of a computer. The three options for entering or accessing task manager in windows are:

1. Press Ctrl+Alt+Delete and then click Task Manager

2. Right-click the taskbar and choose Start Task Manager

3. Right-click the taskbar and choose Manage Tasks

5 0
3 years ago
Write a program that asks the user to enter a birth year. the program should then indicate which generation a person of that yea
USPshnik [31]
Something like the following. Also you need to give what language you are using. Anyways, you should be able to convert this to your language of choice. 

<script type="text/javascript">
function checkGeneration() { 
   var gen = ["Baby Boomer ","Generation X","Xennials","Generation Y"];
   var reversestr = "";
   var getyear = window.prompt("Enter a 3 digit number: ");
    if (parseInt(getyear) <= 1964) {
        alert(gen[0]);   
    } else if(parseInt(getyear) <= 1979) {
        alert(gen[1]);
    } else if(parseInt(getyear) <= 1985) {
        alert(gen[2]);               
   }  else if(parseInt(getyear) <= 1995) {
        alert(gen[3]);
   }
 }
checkGeneration();
</script>
7 0
2 years ago
Why the computer is known as versatile and diligent device ? explain.<br>​
Scrat [10]

Answer:

Computer is called versatile and diligent device because it is used in almost all the fields for various purposes and it can perform the task repeatedly without loosing its speed and accuracy for long time.

5 0
2 years ago
What is what is a network that is easy to maintain and cheap ​
kifflom [539]

Answer:

Click at the pic above and the ans will appear.

Hope it helps :)

4 0
3 years ago
Which of the following need to be assessed during unit testing?
diamong [38]
E) both C and D Erro handling and execution paths
8 0
3 years ago
Other questions:
  • What does an approved project summary document indicate?
    13·1 answer
  • 1. Potential incidents represent threats that have yet to happen. Why is the identification of the threat important to maintaini
    6·1 answer
  • What is the letter for the trash directory on windows 10?
    13·2 answers
  • A student opens a recently purchased software package and begins reading the enclosed materials. What information might be inclu
    6·1 answer
  • How do you merge on excel?​
    5·1 answer
  • If String str = "Computer Science";, then what is the value of str.substring(10);? ​
    6·1 answer
  • Anyone want to play mine mincraft w/ me?
    9·1 answer
  • Which cpu type would most likely be found in a smartphone?.
    10·1 answer
  • Select the correct technical term for each definition by using the drop-down menus.
    13·1 answer
  • a data analyst is working with a spreadsheet that has very long text strings. rather than counting the characters themselves to
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!