a. 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. Create an application that demonstrates each method works correctly.
b. 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 TestFitnessTrackerapplication to ensure that the overloaded constructor works correctly, save it, and then test it.
FitnessTrackers.java
import java.time.*;
public class FitnessTracker {
String activity;
int minutes;
LocalDate date;
public FitnessTracker() {
}
public FitnessTracker(String a, int m, LocalDate d) {
}
public String getActivity() {
}
public int getMinutes() {
}
public LocalDate getDate() {
}
}
TestFitnessTracker.java
import java.time.*;
public class TestFitnessTracker
{
public static void main(String[] args)
{
FitnessTracker exercise = new FitnessTracker();
System.out.println(exercise.getActivity() + " " +
exercise.getMinutes() +
" minutes on " + exercise.getDate());
// code to test constructor added for exercise 3b
LocalDate date = LocalDate.of(2020, 8, 20);
FitnessTracker exercise2 = new FitnessTracker("bicycling", 35,
date);
System.out.println(exercise2.getActivity() + " " +
exercise2.getMinutes() +
" minutes on " + exercise2.getDate());
}
}
Hi,
Here is the code for your assignment. I have added comments in the code for your reference.
The output and screenshot are at the end of this answer.
If you have any questions or need clarifications, leave me a comment.
If this answer helps you with your assignment, spare a moment and upvote this answer.
//File: FitnessTracker.java
import java.time.*;
public class FitnessTracker {
String activity;
int minutes;
LocalDate date;
public FitnessTracker() {
//3a
//set defaults
activity = "running";
minutes = 0;
date = LocalDate.ofYearDay( LocalDate.now().getYear(), 1); //1st
Jan of the year
}
//Parameterized constructor //3b
public FitnessTracker(String a, int m, LocalDate d) {
activity = a;
minutes = m;
date = d;
}
public String getActivity() {
return activity;
}
public int getMinutes() {
return minutes;
}
public LocalDate getDate() {
return date;
}
}
//File: TestFitnessTracker.java
import java.time.*;
public class TestFitnessTracker
{
public static void main(String[] args)
{
FitnessTracker exercise = new FitnessTracker();
System.out.println(exercise.getActivity() + " " +
exercise.getMinutes() +
" minutes on " + exercise.getDate());
// code to test constructor added for exercise 3b
LocalDate date = LocalDate.of(2020, 8, 20);
FitnessTracker exercise2 = new FitnessTracker("bicycling", 35,
date);
System.out.println(exercise2.getActivity() + " " +
exercise2.getMinutes() +
" minutes on " + exercise2.getDate());
}
}
//Output

a. Create a FitnessTracker class that includes data fields for a fitness activity, the number of...
it's a JAVA program.
Share Edit & Create aanmethod that tests all three overloaded methods. Save the application as Billing.java. a. 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...
Problem 1.(1) Implement a class Clock whose getHours and getMinutes methods return the current time at your location. (Call java.time.LocalTime.now().toString() or, if you are not using Java 8, new java.util.Date().toString() and extract the time from that string.) Also provide a getTime method that returns a string with the hours and minutes by calling the getHours and getMinutesmethods. (2) Provide a subclass WorldClock whose constructor accepts a time offset. For example, if you live in California, a new WorldClock(3) should show...
JAVA PROGRAM. Write a program to implement a class Clock whose getHours and getMinutes methods return the current time at your location. Also include a getTime method that returns a string with the hours and minutes by calling the getHours and getMinutes methods. Provide a subclass WorldClock whose constructor accepts a time offset. For example, if you livein California, a new WorldCLock(3) should show the time in NewYork, three time zones ahead. Include an Alarm feature in the Clock class....
(To be written in Java code) Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, ENG) id (int) - the course number (for example, 101) credits (double) - the credits (for example, 3) price (double) - the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display()...
Modify the library program as follows: Create a method in the LibraryMaterial class that accepts a string s as a parameter and returns true if the title of the string is equal to s. Create the same method for your library material copies. Note that it will need to be abstract in the LibraryMaterialCopy class MY CODE **************************************************************** LibraryCard: import java.util.List; import java.util.ArrayList; import java.time.LocalDate; import java.time.temporal.ChronoUnit; public class LibraryCard { private String id; private String cardholderName; ...
Create a class named Poem that contains the following fields: title - the name of the poem (of type String) lines - the number of lines in the poem (of type int) Include a constructor that requires values for both fields. Also include get methods to retrieve field values. Create three subclasses: Couplet, Limerick, and Haiku. The constructor for each subclass requires only a title; the lines field is set using a constant value. A couplet has two lines, a...
Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the type int, assessedPrice of the type double. A constructor for this class should have three arguments for initializing these fields. Add accessors and mutators for all fields except a mutator for yearBuilt, and the method toString. Create a class StreetHouse which extends House and has additional fields: streetNumber of the type int, homeowner of the type String, and two neighbors: leftNeighbor and rightNeighbor, both...
Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races(of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. DemoHorses.java public class DemoHorses { public static void main(String args[])...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...