How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask ATLProg Your Own Question

ATLProg
ATLProg, Software Engineer
Category: Homework
Satisfied Customers: 9151
Experience:  Expert in Java C++ C C# VB Javascript Design SQL HTML
44910485
Type Your Homework Question Here...
ATLProg is online now
A new question is answered every 9 seconds

1)Modify the Module 5 Car class to provide a start() method

This answer was rated:

1)
Modify the Module 5 Car class to provide a start() method that
overrides the Vehicle class start() method and a speedUp() method that
overloads the Vehicle class speedup() method.
The initial code for the Car and Vehicle classes, and the TestCar2 driver class from
Module 5 is shown below.



/**
Vehicle class
This class is used to create Vehicle objects.
*/
public
class
Vehicle
{
// Vehicle class instance fields
private
boolean
moving;
// whether or not the vehicle
is currently moving
private
double
speed;
// speed in mph of the vehicle
private
char
bearing;
// direction vehicle headed
('N','E','S', or 'W')
public
Vehicle()
// Vehicle class no
-
arg constructor
{
moving =
false
;
// assume not moving
speed = 0.0;
// not moving
bearing =
'N'
;
// assume 'N'orth
System.out.println(
"Created a vehicle (no
-
arg)"
);
}
publi
c
Vehicle (
double
initialSpeed)
// Vehicle 1
-
arg
constructor
{
bearing =
'W'
;
speed = initialSpeed;
if
(speed > 0.0)
{
moving =
true
;
}
System.out.println(
"Created a vehicle (1
-
arg)"
);
}
public
Vehicle (
double
initialSpeed,
char
initialBearing)
// Vehicle 2
-
arg constructor
{
bearing = initialBearing;
speed = initialSpeed;
if
(speed > 0.0)
{
moving =
true
;
}
System.out.println(
"Created a vehicle (2
-
arg)"
);
}
public
void
start(
double
initialSpeed,
char
initialBearing)
{
moving =
true
;
if
(initialSpeed >= 5.0 && initialSpeed = 0.0 && initialSpeed < 5.0)
{
speed = 5.0;
// minimum
}
else
if
(initialSpeed 20.0)
{
spe
ed = 20.0;
// maximum allowed
}
switch
(initialBearing)
{
case
'N'
:
bearing = initialBearing;
break
;
case
'E'
:
bearing = initialBearing;
break
;
case
'S'
:
bearing = initialBearing;
break
;
case
'W'
:
bearing = initialBearing;
default
:
System.out.println(
"invalid bearing "
+
initialBearing +
" set to N"
);
// additional
user no
tification
bearing =
'N'
;
}
}
public
double
getSpeed()
// get and return current speed
in mph
{
return
speed;
}
public
void
setSpeed(
double
newSpeed)
// set new speed
in mph
{
speed = newSpeed;
}
public
char
getBearing()
// get and return current
bearing
{
return
bearing;
}
public
void
speedUp(
double
mphSteps,
int
numSteps)
{
int
counter = 0;
while
(counter < numSteps)
{
speed += mphSteps;
System.out.println(
"counter= "
+ counter +
", "
+
this
.toString());
counter++;
}
}
public
String toString()
{
return
"From toString(): speed= "
+ getSpeed() +
" mph and bearing= "
+ getBearing();
}
}
/**
Car class
This class is used to create Car objects and inherits
from the Vehicle class.
*/
public
class
Car
extends
Vehicle
{
// Car class instance fields
private
String color;
// color of the Car
private
int
doors;
// number of doors of the Car
private
double
hp;
// engine horsepower
public
Car(String carColor,
int
numDoors,
double
horsePower,
double
startingSpeed)
// 4
-
arg constructor
{
super
(startingSpeed);
color = carColor;
doors = numDoors;
hp = horsePower;
System.out.println(
"Created a car"
);
}
public
String getColor()
{
return
color;
}
public
int
getDoors()
{
return
doors;
}
publ
ic
double
getHp()
{
return
hp;
}
public
String toString()
{
return
"From Car toString(): color= "
+ getColor() +
" doors= "
+ getDoors() +
" hp= "
+ getHp() +
" speed= "
+ getSpeed() +
" mph and bearing= "
+ getBearing();
}
}
/**
TestCar2 class
This class is used to create a Car, start it up, and then
speed it up.
*/
public
class
TestCar2
{
public
static
void
main(String[] args)
{
// create, start, and speed up a Car
Car myCar2 =
new
Car(
"blue"
, 4, 300., 10.0);
// blue
car, 4 doors, 300. hp
// w/
initial speed of 10 mph
System.out.println(myCar2.toString());
myCar2.speedUp(5.0, 2);
}
}

The Car class’s
overriding start() method must start a car in a southerly direction at zero
speed. The Car class’s overloaded speedup() method should just accept the additional
miles per hour that the car should start moving from its current speed. Modify the
TestCar2 driver class to form a new TestCar3 driver class that creates a myCar3 instance and uses single start() and single speedup() method calls to use the Car class’s start() and speedup() methods only to accelerate it by 50 mph.

Be sure that you include the course, the program number, your name, and the date in your program header. Include additional comments as necessary and maintain consistent
indentation for good programming style as shown in the text. Be sure that you capture
all of your output for this program's execution for full credit
Hello Welcome. Thank you for your question, I’m ATLProg and I’ll try to help you.
Can you please let me know how soon you need this done.
Customer: replied 3 years ago.

By midnight tonight MST if possible


 

ok will be done by then
Customer: replied 3 years ago.

Thank you

stay here...I can send it now
Download Answer Link I hope I’ve provided the information you were seeking. If you are happy with my service, please provide a rating. If not, please let me know so l can continue to help you. Thank you.
Customer: replied 3 years ago.

I cant access the files

What happens when you click link?
THIS ANSWER IS LOCKED!

You need to spend $3 to view this post. Add Funds to your account and buy credits.
ATLProg and 2 other Homework Specialists are ready to help you

Related Homework Questions