Question: Inheritance Java Programming These are the codes that I wrote from the previous assignment, since this assignment is a build up from the previous assignment:

Inheritance Java Programming Inheritance Java Programming These are the codes that I wrote from the previous assignment, since this assignment is a build up from the previous assignment: public class Sport { // Instance variables private String activity; private

int calories; //2 constructors private static int count = 0; public Sport()

These are the codes that I wrote from the previous assignment, since this assignment is a build up from the previous assignment:

public class Sport { // Instance variables private String activity; private int calories; //2 constructors private static int count = 0; public Sport() { count++; } Sport(Sport s){ this.activity = s.activity; this.calories = s.calories; count++; } // GETTERS & SETTERS public Sport(String a, int c) { activity = a; calories = c; count++; } public String getActivity() { return activity; } public void setActivity(String activity) { this.activity = activity; } public int getCalories() { return calories; } public void setCalories(int calories) { this.calories = calories; } //TOSTRING METHOD public String toString(){ return "Activity: "+ activity +" Calories: " + calories; } public static int sportObjects(){ return count; } public boolean sameCaloriesExpended(Sport s){ if(this.calories == s.calories){ return true; } else{ return false; } } }

/* SportProgram2.java * * driver program for inheritance version of Sport */ public class SportProgram2 { public static void main (String [] args) { // create sport objects Sport s0 = new IndividualSport(); Sport s1 = new IndividualSport("swimming", 817, 3); Sport s2 = new IndividualSport("running", 1022, 1); Sport s3 = new IndividualSport("snowshoeing", 654, 2); Sport s4 = new TeamSport(); Sport s5 = new TeamSport("football", 735, 11, 60); Sport s6 = new TeamSport(); Sport s7 = new IndividualSport("swimming", 817, 2); // use getters and setters System.out.println(" Sport s0 is " + s0.getActivity() + " and it burns " + s0.getCalories() + " calories"); System.out.println("The calories for s0 is being changed to 515 for a " + "slower walking rate"); s0.setCalories(515); System.out.println("Sport s0 now burns " + s0.getCalories() + " calories per hour"); // compare calories burned for different sports System.out.println(" Sport s3 is " + s3.getActivity() + " and it burns " + s3.getCalories() + " calories"); String value = (s0.sameCaloriesExpended(s3)) ? "" : "not "; System.out.println("Doing s0 or s3 will " + value + "burn the same number of calories"); System.out.println("Sport s4 is " + s4.getActivity() + " and it burns " + s3.getCalories() + " calories"); value = (s3.sameCaloriesExpended(s4)) ? "" : "not "; System.out.println("Doing s3 or s4 will " + value + "burn the same number of calories "); // use static variable to get number of objects System.out.println("There are " + Sport.sportObjects() + " Sport objects"); /* inheritance-related test code */ // print properties using subclass versions of toString() System.out.println("Here are the properties of the Sport objects: "); Sport [] sports = {s0, s1, s2, s3, s4, s5, s6, s7};; for (int i = 0; i   inheritance 1) create a TeamSport class that extends Sport and contains the following: two instances variables players: number of players on team time: number of minutes of player two constructors no argument: default values of basketball, 654, 5, 40 argument: user-supplied values for activity, calories, players, time two getters two setters toString0 override the equals0 method from object and have it return true if both TeamSport objects have the same number of players and minutes of play: public boolean equals (object o) override the abstract method from Sport: public double computeCalories0 using the following formula: calories (minutes played overtime) calories per hour portion of hour where overtime 0 to 5 five-minute sessions (where number is chosen randomly)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!