Academic coaching, editing, and research guidance for university students.

answered: Create a FitnessTracker class that includes data fields for

2 min read
  

Create a FitnessTracker class that includes data fields for a fitness activity, the number of minutes spent participating, and the date. The class includes methods to get each field. In addition, create a default constructor that automatically sets the activity to running, the minutes to 0, and the date to January 1 of the current year. Save the file as FitnessTracker.java. Create an application that demonstrates each method works correctly, and save it as TestFitnessTracker.java.
Create an additional overloaded constructor for the FitnessTracker class you created in Exercise 3a. This constructor receives parameters for each of the data fields and assigns them appropriately. Add any needed statements to the TestFitnessTracker application to ensure that the overloaded constructor works correctly, save it, and then test it.
Modify the FitnessTracker class so that the default constructor calls the three-parameter constructor. Save the class as FitnessTracker2.java. Create an application to test the new version of the class, and name it TestFitnessTracker2.java.
The solution requires (4) files. Two class files (very similar) and two test programs.
In the class file you’ll need to import the time methods, java.time.*;. Next, you need to define the variables, String Activity, double for minutes, LocalDate date; for the date. Then define the default constructor for the activity Running, minutes = 0; and date = LocalDate.of(2022,1,1);.
Then you need to define the FitnessTracker method (String a, double m, LocalDate d) { body of method, you can nail this.}.
Then you’ll need three methods, getActivity(), getMinutes(), and public LocalDate getDate().
In the main program, instantiate an object: FitnessTracker exercise = new FitnessTracker();
Then print the values from the default constructor object System.out.println(exercise.getActivity() + ” “……);
Then you need another exercise,
LocalDate date = LocalDate.of(2022, 8, 5); // gets the date
FitnessTracker exercise2 = new FitnessTracker(“Bicycling”, 65.55, date);
Then print the results.

Academic integrity note

Use this educational resource to build your understanding. Follow your institution’s rules and cite sources appropriately.

Want feedback on your own work?

Request Academic Support

Leave a Reply

Your email address will not be published. Required fields are marked *