Question
2.34 LAB: Simple car Given two integers that represent the miles to drive forward and the miles to drive in reverse as user inputs, create
2.34 LAB: Simple car
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
LabProgram.java
import java.util.Scanner;
public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); /* Type your code here. */
HELP WITH THIS SECTION
} }
SimpleCar.java
// 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"); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started