Home / Expert Answers / Computer Science / running-this-code-and-receiving-this-error-i-have-tried-over-and-over-and-nothing-what-am-i-doing-pa315

(Solved): RUNNING THIS CODE AND RECEIVING THIS ERROR, I HAVE TRIED OVER AND OVER AND NOTHING. WHAT AM I DOING ...



RUNNING THIS CODE AND RECEIVING THIS ERROR, I HAVE TRIED OVER AND OVER AND NOTHING. WHAT AM I DOING WRONG?
PLEASE HELP IN JAVA. 

Program Specifications Write a FancyCar class to support basic operations such as drive, add gas, honk horn, and start engineFailed to compile
LabProgram.java:82: error: duplicate class: LabProgram
public class Laberogram \( \mid \)
Eancycar.java:1: class LabProgram {
   public static void main(String[] args) {
      FancyCar car = new FancyCar();
      car.drive(50);
      System.out.println("Miles driven: " + car.checkOdometer());
      System.out.println("Gas Tank: " + car.checkGasGauge() + " gallons");
      
      /* Add statements as methods are completed to support development mode test */ 
      
   }
}
class FancyCar{
// declaring variables
int miles;
double gallons, mpg, capacity;
String model;
boolean status;
int FULL_TANK = 14;

//default constructor
FancyCar(){
miles = 5;
gallons = FULL_TANK;
mpg = 24;
model = "Old Clunker";
status = false;
}
//Second constructor
FancyCar(String model, double mpg){
this.model = model;
this.mpg = mpg;
}

//Methods of car
int checkOdometer(){
return miles;
}

double checkGasGuage(){
return gallons;
}
String getCarModel(){
return model;
}
double getMPG(){
return mpg;
}
void honkHorn(){
System.out.println("The "+model+" says beep beep");
}

//drive method
int drive(int milesToDrive){
double milesCanDrive = mpg * gallons;
if(milesCanDrive >= milesToDrive)
miles += milesToDrive;
else
miles += milesCanDrive;
gallons -= miles/mpg;
return miles;
}

double addGas(int amtToAdd){
if(amtToAdd > 0 && status == false){
gallons += amtToAdd;
}
if (gallons > FULL_TANK){
gallons = FULL_TANK;
}
return gallons;
}

boolean startEngine(){
return status = true;
}

boolean stopEngine(){
return status = false;
}

}
public class LabProgram {
public static void main(String[] args) {
FancyCar car = new FancyCar();
car.drive(50); 
System.out.println("Miles driven: "+car.checkOdometer());
System.out.println("Gas Tank: "+car.checkGasGuage()+" gallons");

car.honkHorn();
System.out.println("Model: "+car.getCarModel());
System.out.println("MPG: "+car.getMPG());

System.out.println("Miles to Drive: "+car.drive(3));
System.out.println("Gallons after add gas: "+car.addGas(20));

System.out.println("Start Engine: "+car.startEngine());
System.out.println("Stop Engine: "+car.stopEngine());
}
}

Program Specifications Write a FancyCar class to support basic operations such as drive, add gas, honk horn, and start engine. FancyCar.java is provided with method stubs. Follow each step to gradually complete all methods. Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Onlly a portion of tests pass after each step but confirm progress. The main0 method includes basic method calls. Add statements in main0 as methods are completed to support development mode testing. Step 0. Declare private fields for miles driven as shown on the odometer (int), gallons of gas in tank (double), miles per gallon or MPG (double), driving capacity (double), and car model (String). Note the provided final variable indicates the gas tark capacity of \( 14.0 \) gallons. Step 1 (2 pts). 1) Complete the default constructor by initializing the odometer to five miles, tank is full of gas, miles per gallon is 24.0, and the model is "Old Clunker". 2) Complete the second constructor by passing the model (String) and miles per gallon (double), and initializing all other private fields the same as the default constructor. 3) Complete the accessor methods to check the odometer, check the gas guage, get the model, and get the miles per gallon. Submit for grading to confirm 2 tests pass. Step 2 (1 pt). Complete the honkHom() method to output the car model. Calling the honkHorn() method uses the model private field to provide the following output: The Honda Civic says beep beep! Submit for grading to confirm 3 tests pass. Step 3 (1 pt). Complete the driven method. Miles driven should increase by parameter distance and amount of gas should decrease by distance / MPG. Variables are only updated if parameter distance is positive. Submit for grading to confirm 4 tests pass. Step 4 (2 pts). Complete the addGas0 method. Increase gas tank by parameter amount only if parameter is positive. Set gas tank to FULL if too much gas was added. Submit for grading to confirm 5 tests pass. Step 5 (2 pts). Update the drive() method to identify if the car runs out of gas. If so, the parameter distance will not be achieved and the gas tank will have \( 0.0 \) gallons. Ex: drive(100) will not be possible with only three gallons of gas and MPG of 20.0. The maximum driving distance is 60 miles with three gallons of gas and MPG of \( 20.0 \). Therefore, the odometer will only increase by 60 instead of the requested 100 and the gas tank will have \( 0.0 \) gallons (not a negative amount). Submit for grading to confirm 6 tests pass. Step 6 (2 pts). 1) Add a boolean private field to indicate if the car engine is on or off. 2) Complete the startEngine() method to set the boolean variable to true. 3) Complete the stopEngine() method to set the boolean variable to false. 4) Update the constructors to start with the engine off. 5) Update the drive(0 method to only update private fields if the engine is on, and the engine turns off if the car runs out of gas. 6) Update the addGas(0 method to only add gas if the engine is off. Submit for grading to confirm all tests pass. \( 412158.1658798 . q \times 3 z \) qyy \begin{tabular}{|l|l|l|l|l|l|} LAB & 2.23.1: LAB* Program: Fancy car & \( 0 / 10 \) \end{tabular} Current file: LabProgram_java * \( \quad \) Load default template.. 1 class LabProgram \{ public static void main(String \( \square \) args) ( FancyCar car \( = \) new FancyCar(); car. drive(50); System.out.println("Miles driven: " + car. check0dometerO); System. out.println("Gas Tank: " + car. checkGasGauge() +" gallons"); * Add statements as methods are completed to support development mode test * 3 \} Failed to compile LabProgram.java:82: error: duplicate class: LabProgram public class Laberogram \( \mid \) Eancycar.java:1: error: duplicate class: Eancycar public class Eancycarb Laberogram.java:6: error: cannot find symbol Systen. out.println ("Gas Tank: " + car. checkGasGauge(\}+ \( + \) " gallons") symbol: method checkGasGauge() location: variable car of type Eancycar 3 errors


We have an Answer from Expert

View Expert Answer

Expert Answer


The above error occurs because you have another class called La
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe