I need a superclass and subclasses. Thank you!! The two most navigator a week an
ID: 3703743 • Letter: I
Question
I need a superclass and subclasses. Thank you!! The two most navigator a week and spaceship navi Cloud dusters wear uniforms which are either gray or wear goggles that are either ultraviolet. You common occupations on planet Galax are and each has its cloud duster and spaceship own hourly rate. Cloud dusters work between 3 and 8 hours gators either 11 or 17, both values being randomly chosen. black, and spaceship navigators trate how ier infrared or ultraviolet. You decide to use this example to method and output: public static void main (String [1 args) Worker c new CloudDuster(10.8, "gray") Worker s new SpaceshipNavigator(14.2, "infrared"): System.out.printin(nc's uniform color is ((CloudDuster)c).getUniform)+n); (SpaceshipNavigator)s).setGoggles("ultraviolet) Worker [1 crew (c, s); for (Worker w: crew) System.out.printin("joblt"+ w.getClass0.getName)): System.out.printin(w); System.out.printf("c's pay for this week is %6.2f", ?.computeEarnings()); System.out.printf("ins's pay for this week is %6.2rn", s.computeEarningsO); c's uniform color is gray job rate CloudDuster 10.8 uniform gray job rate SpaceshipNavigator 14.2 goggles ultraviolet c's pay for this week is 75.60 s's pay for this week is 156.20 you write the classes that it uses....Explanation / Answer
`
class Worker//Sample Worker class which extended by CloudDuster and SpaceshipNavigator
{
public static void main(String args[])//Main Function you have given
{
Worker c = new CloudDuster(10.8,"gray");
Worker s = new SpaceshipNavigator(14.2,"infrared");
System.out.println(" c's uniform color is "+((CloudDuster)c).getUniform()+" ");
((SpaceshipNavigator)s).setGoogles("ultravoilet");
Worker [] crew = {c,s};
for(Worker w:crew)
{
System.out.println("===============================");
System.out.println("job "+w.getClass().getName());
if(w.getClass().getName()=="CloudDuster")//for changing w to respective class and print details
{
System.out.println("Rate "+((CloudDuster)w).getRate());
System.out.println("Uniform "+((CloudDuster)w).getUniform());
}
else
{
System.out.println("Rate "+((SpaceshipNavigator)w).getRate());
System.out.println("Googles "+((SpaceshipNavigator)w).getGoogles());
}
System.out.println("===============================");
}
System.out.printf("c's pay for this week is %6.2f",((CloudDuster)c).computeEarnings());
System.out.printf(" s's pay for this week is %6.2f",((SpaceshipNavigator)s).computeEarnings());
}
}
class CloudDuster extends Worker
{
//class CloudDuster as explained contains rate and uniform
double rate;
String uniform;
CloudDuster(double time,String color)
{
this.rate = time;
this.uniform = color;
}
String getUniform()
{
return this.uniform;
}
double getRate()
{
return this.rate;
}
double computeEarnings()
{
return this.rate*7;
}
}
class SpaceshipNavigator extends Worker
{
//Class SpaceshipNavigator which extends Worker class and contains rate and googles
double rate;
String googles;
SpaceshipNavigator(double time,String color)
{
this.rate = time;
this.googles = color;
}
void setGoogles(String color)
{
this.googles = color;
}
void setRate(double time)
{
this.rate = time;
}
double computeEarnings()
{
return this.rate*11;
}
String getGoogles()
{
return this.googles;
}
double getRate()
{
return this.rate;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.