Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I'm having trouble with my coding here, I try to run it and it doesn't work. Can someone help me? Thank you import java.util.Scanner;

Hi, I'm having trouble with my coding here, I try to run it and it doesn't work. Can someone help me?

Thank you

import java.util.Scanner;

public class Automobile {

public static void main(String[]args) {

}

private int idNumber;

private String make;

private String model;

private String color;

private int year;

private String vinNumber;

private double milesPerGallon;

private int speed;

private int brake;

Scanner input = new Scanner(System.in);

//Do not allow the ID to be negative or more than 9999.

//Set ID to 0

//Do not allow the year to be earlier than 2000 or later than 2017.

//Set year to 0.

public Automobile (int id, String mke, String mdl, String clr, int yr, String vin, int mpg)

{

idNumber = id;

make = mke;

model = mdl;

color = clr;

year = yr;

vinNumber = vin;

milesPerGallon = mpg;

speed = 0;

}

public void setIdNumber(int id)

{

idNumber = id;

}

public int getIdNumber()

{

if(idNumber < 0 || idNumber > 9999)

idNumber = 0;

return idNumber;

}

public void setMake(String mke)

{

make = mke;

}

public String getMake()

{

return make;

}

public void setModel(String mdl)

{

model = mdl;

}

public String getModel()

{

return model;

}

public void setColor(String clr)

{

color = clr;

}

public String getColor()

{

return color;

}

public void setYear(int yr)

{

year = yr;

}

public int getYear()

{

if(year < 2000 || year > 2017)

year = 0;

return year;

}

public void setVinNumber(String vin)

{

vinNumber = vin;

}

public String getVinNumber()

{

return vinNumber;

//Do not allow the miles per gallon to be less than 10 or more than 60, set miles per gallon to 0.

}

public void setMilesPerGallon(double mpg)

{

milesPerGallon = mpg;

}

public double getMilesPerGallon()

{

if(milesPerGallon < 10 || milesPerGallon > 60)

milesPerGallon = 0;

return milesPerGallon;

//Speed arguments with accelerate and brake

}

public void setSpeed(int spd)

{

speed = spd;

}

public int getSpeed()

{

if(speed < 0)

speed = 0;

return speed;

}

public int accelerate()

{

speed = speed + 5;

System.out.println("Current speed is: " + speed);

return speed;

}

public int accelerate(int accl)

{

speed = speed + accl;

System.out.println("Current speed is: " + speed);

return speed;

}

public int brake()

{

speed = speed - 5;

if(brake < 0)

brake = 0;

System.out.println("Current speed is: " + speed);

return speed;

}

public int brake(int brk)

{

speed = speed - brk;

if(brake < 0)

brake =0;

System.out.println("Current speed is: " + speed);

return speed;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions