Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

@ describe the budgetary process

Answered: 1 week ago

Question

What is the effect of word war second?

Answered: 1 week ago