Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble resolving some issues with this java program. the below is my first class Automobile and then my second class. I keep

I am having trouble resolving some issues with this java program. the below is my first class Automobile and then my second class. I keep getting an undefined error for my object new automobile in the AutomobileTest class. can you help?

Here is my assignment

make an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per gallon, 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.

import java.util.Scanner;

public class AutomobileSKI{

private double year, idNumber, vinNumber,speed, milesPerGallon;

private String make, model,color;

public AutomobileSKI(double IDNum, String carMake, String carModel, double carYear, String CarColorolor, double carVinNumber, double MPG, double carSpeed){

IDNum = idNumber;

carMake = make;

carModel = model;

CarColorolor = color;

carVinNumber = vinNumber;

MPG = milesPerGallon;

speed = 0;

carYear = year;

double speedUp;

double speedDown;

double incSpeed;

double decSpeed;

double newSpeed;

speedUp =accelerate (speed);

speedDown =decelerate (speed);

incSpeed = accelerate (speedUp,speed);

decSpeed = decelerate (speedDown,speed);

}

Scanner inputDevice = new Scanner(System.in);

//setter methods

public void setIdNumber( double IDNum){

if (idNumber > 0 || idNumber < 1000){

IDNum = 0;

System.out.println ("Please enter Vin Number >>");

vinNumber = inputDevice.nextDouble();

}

this.idNumber= IDNum;

}

public void setMake (String carMake) {

this.make = carMake;

System.out.println ("Please enter make >>");

make = inputDevice.nextLine();

}

publicvoid setYear(double carYear){

if (year >=2000 || idNumber <= 2017){

year = 0;

System.out.println ("Please enter year of car>>");

year = inputDevice.nextDouble();

}

this.year = carYear;

}

public void setColor(String carColor){

this.color = carColor;

System.out.println ("Please enter color >>");

color = inputDevice.nextLine();

}

public void setVinNumber( double carVinNumber){

this.vinNumber = carVinNumber;

System.out.println ("Please enter Vin Number >>");

vinNumber = inputDevice.nextDouble();

}

public void setModel (String carModel) {

this.make = carModel;

System.out.println ("Please enter model >>");

model = inputDevice.nextLine();

}

public void setSpeed (double carSpeed) {

this. speed = carSpeed;

System.out.println ("Please enter Speed >>");

speed = inputDevice.nextDouble();

}

public void setMilesPerGallon( double MPG){

if(milesPerGallon>= 10 || milesPerGallon <= 60){

milesPerGallon = 0;

System.out.println ("Please enter Miles per gallon >>");

milesPerGallon = inputDevice.nextDouble();

}

this.milesPerGallon = MPG;

}

//. Include a constructor that accepts arguments for each field value and uses the set methods to assign the values

// Getter methods

public double getIdNumber(){

return idNumber;

}

public String getMake(){

return make;

}

publicdouble getYear(){

return year;

}

publicString getColor(){

return color;

}

publicdouble getVinNumber(){

return vinNumber;

}

publicdouble getMilesPerGallon(){

return milesPerGallon;

}

public String getModel(){

return model;

}

public double getSpeed(){

return speed;

}

// speed adjust merthods

publicdouble accelerate(double speed){

double speedUp = speed + 5;

return speedUp;

}

public double accelerate(double speedUp, double speed){ double acc;

Scanner inputDevice = new Scanner(System.in);

System.out.println ("Please enter desied speed increse");

acc = inputDevice.nextDouble();

double incSpeed = speed + acc;

return incSpeed;

}

publicdouble decelerate(double Speed){

double speedDown = speed - 5;

return speedDown;

}

public double decelerate(double speedDown, double Speed ){ double dec;

Scanner inputDevice = new Scanner(System.in);

System.out.println ("Please enter desired speed decrease");

dec = inputDevice.nextDouble();

double decSpeed = speed - dec;

return decSpeed;

}

}

------------------------------------------------------------------

------------------------------------------------------------------

import java.util.Scanner;

public class TestAutomobileSKI{

public void main(String[] args){

Automobile carOne = new Automobile ( carOne.getYear() + carOne.getColor() + carOne.getMake() + carOne.getModel() + carOne.getIdNumber() + carOne.getVinNumber() + carOne.getMilesPerGallon() + carOne.getSpeed());{

}

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

Step: 3

blur-text-image

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

Question

Pafrd_in-e

Answered: 1 week ago

Question

1. What is Ebola ? 2.Heart is a muscle? 3. Artificial lighting?

Answered: 1 week ago