Question: Design a class named Spacecraft that contains: A private String data field named spacecraftName for the spacecraft. A private int data field named fuelLevel that
Design a class named Spacecraft that contains:
A private String data field named spacecraftName for the spacecraft.
A private int data field named fuelLevel that stores the current fuel level (default 0).
A private double data field named speed that stores the current speed (default 0). Assume all spacecraft have the same speed.
A private Date data field named dateLaunched that stores the date when the spacecraft was launched.
A no-arg constructor that creates a default spacecraft and initializes the spacecraftName with a name with the format "Cruz Galactica - " + a random 4 digit number.
Aone-argument constructor that creates a spacecraft with a specific initial fuel level (constructor argument) and initializes the spacecraftName with a name with the format "Cruz Galactica - " + a random 4 digit number.
Atwo-argument constructor that creates a spacecraft with a specific initial fuel level and speed (constructor arguments) and initializes the spacecraftName with a name with the format "Cruz Galactica - " + a random 4 digit number.
The accessor and mutator methods for fuelLevel and speed.
The accessor methods for dateLaunched and spacecraftName.
A method named accelerate(double) that increases the speed of the spacecraft by a specified amount.
A method named refuel(int) that refuels the spacecraft by a specified amount.
Write a test program class TestSpacecraft) that creates a Spacecraft object with a fuel level of 50,000 units and a speed of 500 units per second. Use the accelerate method to increase the speed by 100 units per second, use the refuel method to add 10,000 units of fuel, and then print the spacecraft name, fuel level, speed, and the date it was launched (use console output).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
