Given two integers that represent the miles to drive forward and the miles to drive in reverse as user inputs, create a SimpleCar object that performs the following operations: Drives input number of miles forward Drives input number of miles in reverse Honks the horn Reports car status The SimpleCar class is found in the file SimpleCar.java. Ex: If the input is: 100 4 the output is: beep beep Car has driven: 96 miles // Simulates a simple car with operations to drive and check the odometer. public class SimpleCar {        // Number of miles driven    private int miles;        public SimpleCar(){       miles = 0;    }    public void drive(int dist){       miles = miles + dist;    }      public void reverse(int dist){       miles = miles - dist;    }        public int getOdometer(){       return miles;    }    public void honkHorn(){       System.out.println("beep beep");    }    public void report(){       System.out.println("Car has driven: " + miles + " miles");    }     }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

Given two integers that represent the miles to drive forward and the miles to drive in reverse as user inputs, create a SimpleCar object that performs the following operations:

  • Drives input number of miles forward
  • Drives input number of miles in reverse
  • Honks the horn
  • Reports car status

The SimpleCar class is found in the file SimpleCar.java.

Ex: If the input is:

100 4

the output is:

beep beep Car has driven: 96 miles

// Simulates a simple car with operations to drive and check the odometer.
public class SimpleCar {
   
   // Number of miles driven
   private int miles;
   
   public SimpleCar(){
      miles = 0;
   }

   public void drive(int dist){
      miles = miles + dist;
   }
 
   public void reverse(int dist){
      miles = miles - dist;
   }
   
   public int getOdometer(){
      return miles;
   }

   public void honkHorn(){
      System.out.println("beep beep");
   }

   public void report(){
      System.out.println("Car has driven: " + miles + " miles");
   }
   
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,