224k views
5 votes
In this exercise, you will write a class that represents how you spend your time during the week The class should have four double instance variables . . sleep fun School sports These variables will track the number of hours you spend doing each of these activites in a single day, respectively The class should also have the following methods • A constructor that has no parameters public void setsleept double hours Sleep) public vold setFun(double hourstun public void set School(double hours School) public void set Sports (double hours Sports) mbate vota print Total) The constructor should initialize all of the instanco variables to 0 The methods that begin with "set" set the values of the corresponding instance variables to the value of the parameter The last method should print the total number of hours per week you spend doing each of these activities Note you will have to calculate the weekly hours by using the daily hours stored in the instance variables. It should also print the . . . . public void set School Buble hours School) Dublic void set Sports (double hours Sports) Dublic vota print Total The constructor should initialize all of the instance valables to o The methods that begin with "set" set the values of the corresponding instance variables to the value of the parameter The last method should point the total number of hours per week you spend doing each of these activities Note you will have to calculate the weekly hours by using the daily hours stored in the instance variables it should also print the total number of hours in the week accounted for and how many hours are left over Here is an example of the output of print Totate 3, chool - 8 = 2 and sports = 3 Weekly Totais STED School Dort Funt Ora Tot turto 0

User MERM
by
8.0k points

1 Answer

6 votes

Answer:

Answered below

Step-by-step explanation:

# Program is written in Java

class WeekHours{

double school;

double fun;

double sleep;

double sports;

WeekHours( ){

school = 0.0;

fun = 0.0;

sleep = 0.0;

sports = 0.0;

}

public void setSchool ( double x){

school = x;

}

public void setFun( double y){

fun = y;

}

public void setSleep( double w){

sleep = w;

}

public void setSports( double z){

sports = z;

}

public void totalHours(){

double tHours = school + fun + sleep + sports;

System.out.print(tHours);

}

}

User Lehks
by
7.5k points