Question
For this assignment, you will create a Dashboard class that has a speedometer, an odometer, and a check engine light. In previous assignments, you had
For this assignment, you will create a Dashboard class that has a speedometer, an odometer, and a check engine light.
In previous assignments, you had to name the class "Main", for this assignment you will need to name the class "Dashboard". Please download the template Dashboard.java (https://s3.amazonaws.com/term.2/week02/Dashboard.java)Links to an external site. and add the following constructors and methods.
Constructors
Dashboard() - this is like getting a brand new car! Its not moving and has no miles on it, so both odometer and speedometer should be set to zero. The check engine light should be off.
Dashboard(int milesTravelled, int speed) - If milesTravelled is between 0 and 99999 (inclusive), set the odometer to milesTravelled, otherwise, set it to zero and turn on the check engine light. If speed is between 0 and 100 (inclusive), set the speedometer to speed, otherwise, set it to zero and turn on the check engine light. The check engine light should be off if both values are valid.
Methods
void accelerate() - increases speed by one mile per hour. If the car accelerates above 100mph, the car should stall out and go back to 0mph, and the check engine light should turn on.
void drive(int numMinutes) - drives the car for numMinutes minutes at the current speed. Updates odometer accordingly (rounded down to the mile). Odometer reading cannot exceed 99999, if this happens it rolls back to zero, and the check engine light comes on. numMinutes will not exceed 720 (12 hours). For example, if the current speed is 60 miles per hour, and numMinutes is 20, then the car drives for 20 minutes = 20 miles. The odometer reading should increase by 20 miles.
String toString() - displays the current reading of the speedometer, odometer, and check engine light in the following format. The odometer reading must always have five digits, even if the miles driven take fewer.
Speedometer: 75 MPH Odometer: 06743 Check Engine: Off Speedometer: 6 MPH Odometer: 78967 Check Engine: On
Testing and Submission
To test your code, download the runner class student_dashboard_runner.java (https://s3.amazonaws.com/term.2/week02/student_dashboard_runner.java)Links to an external site. into the same folder that holds your Dashboard.java. Execute the method student_dashboard_runner.main, and verify that the output matches the sample run listed below.
We will use a similar but different runner to grade the program. In order to pass all tests, you will need to change student_dashboard_runner.java (Links to an external site.)Links to an external site. to test different values to make sure your program fits the requirements. Note: You will not be submitting student_dashboard_runner.java (Links to an external site.)Links to an external site.. This file is provided to help you test your implementation of the class Dashboard.
When you are done coding and testing, copy and paste your entire Dashboard class into the Code Runner and press "Submit Answers" in order for your assignment to count as turned in.
Sample Run
DASHBOARD 1 ************************** Speedometer: 0 MPH Odometer: 00000 Check Engine: Off DASHBOARD 2 ************************** Speedometer: 99 MPH Odometer: 15000 Check Engine: Off Speedometer: 100 MPH Odometer: 15000 Check Engine: Off Speedometer: 0 MPH Odometer: 15000 Check Engine: On DASHBOARD 3 ************************** Speedometer: 45 MPH Odometer: 00000 Check Engine: On DASHBOARD 4 ************************** Speedometer: 45 MPH Odometer: 00000 Check Engine: On DASHBOARD 5 ************************** Speedometer: 0 MPH Odometer: 02500 Check Engine: On DASHBOARD 6 ************************** Speedometer: 0 MPH Odometer: 00300 Check Engine: On DASHBOARD 7 ************************** Speedometer: 60 MPH Odometer: 00000 Check Engine: Off Speedometer: 60 MPH Odometer: 00020 Check Engine: Off DASHBOARD 8 ************************** Speedometer: 60 MPH Odometer: 99999 Check Engine: Off Speedometer: 60 MPH Odometer: 00000 Check Engine: On
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