Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick Reference have

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.
Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.
The Bus class simulates the activity of a bus. A bus moves back and forth along a single route, making stops along the way. The stops on the route are numbered consecutively starting from 1 up to and including a number that is provided when the Bus object is created. You may assume that the number of stops will always be greater than 1.
The bus starts at the first stop and is initially heading toward the last stop. At each step of the simulation, the bus is at a particular stop and is heading toward either the first or last stop. When the bus reaches the first or last stop, it reverses direction. The following table contains a sample code execution sequence and the corresponding results.
\table[[Statement or Expression,\table[[Value returned],[(blank if no],[value)]],Comment],[Bus bus1= new Bus (3);,,\table[[The route for bus 1 has three stops],[numbered 1-3.]]],[bus1. getCurrentstop ();,1,bus 1 is at stop 1(first stop on the route).],[bus 1. move ();,,bus 1 moves to the next stop (2).],[bus1.getCurrentstop ();,2,bus 1 is at stop 2.],[bus 1. move ();,,bus 1 moves to the next stop (3).],[bus1. getCurrentstop ();,3,bus 1 is at stop 3.],[bus1. move ();,,bus 1 moves to the next stop (2).],[bus1.getCurrentstop ():,2,bus 1 is at stop 2.],[bus 1. move ();,,bus 1 moves to the next stop (1).],[bus 1. move ();,,bus 1 moves to the next stop (2).],[bus1. getCurrentstop ();,2,bus 1 is at stop 2.],[bus1. getCurrentstop ();,2,bus 1 is still at stop 2.],[Bus bus2= new Bus (5);,,\table[[The route for bus 2 has five stops],[numbered 1-5.]]],[bus1.getCurrentstop ();,2,bus 1 is still at stop 2.],[bus2. getCurrentstop ();,1,bus 2 is at stop 1(first stop on the route).]]
Write the complete Bus class, including the constructor and any required instance variables and methods. Your implementation must meet all specifications and conform to the example.
image text in transcribed

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions