Question

Share Edit & Create aanmethod that tests all three overloaded methods. Save the application as Billing.java. a. Create a Fitn

Exercises b. Create an additional overloaded constructor for the FitnessTracker class you created in Exercise 3a. This constr

it's a JAVA program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a.

class FitnessTracker
{
   private String activity;
   private int numOfMinutes;
   private String date;
  
   //default constructor
   public FitnessTracker()
   {
       activity = "running";
       minutes = 0;
       date = "January 1, 2019";
      
   }

public String getActivity()
   {
       return activity;
   }
   public int getNumOfMinutes()
   {
       return numOfMinutes;
   }
   public String getDate()
   {
       return date;
   }

}
b.

// overloaded constructor
   public FitnessTracker(String activity,int numOfMinutes, String date)
   {
       this.activity = activity;
       this.numOfMinutes = numOfMinutes;
       this.date = date;
   }
  

c.

class FitnessTracker2
{
   private String activity;
   private int numOfMinutes;
   private String date;
  
   //default constructor
   public FitnessTracker2()
   {
      
       this("running",0,"January 1, 2019"); // calling parameter constructor using this
      
   }
   // overloaded constructor
   public FitnessTracker2(String activity,int numOfMinutes, String date)
   {
       this.activity = activity;
       this.numOfMinutes = numOfMinutes;
       this.date = date;
   }
   public String getActivity()
   {
       return activity;
   }
   public int getNumOfMinutes()
   {
       return numOfMinutes;
   }
   public String getDate()
   {
       return date;
   }
  
}
class TestFitnessTracker
{
   public static void main (String[] args)
   {
       FitnessTracker2 f = new FitnessTracker2();
      
       System.out.println("Fitness activity : "+f.getActivity());
       System.out.println("Number of minutes : "+f.getNumOfMinutes());
       System.out.println("Date : "+f.getDate());
      
      
   }
}

Output:

Fitness activity : running
Number of minutes : 0
Date : January 1, 2019

Do ask if any doubt. Please upvote.

Add a comment
Know the answer?
Add Answer to:
it's a JAVA program. Share Edit & Create aanmethod that tests all three overloaded methods. Save...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a. Create a FitnessTracker class that includes data fields for a fitness activity, the number of...

    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...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • Java program. Mike's Movie Theater is a local cinema showing the latest Hollywood hits. Create a...

    Java program. Mike's Movie Theater is a local cinema showing the latest Hollywood hits. Create a class called Movie that stores basic information about a single movie: the title, the running time or length of the film (in minutes), the showtimes (as a single string, such as "11:00,3:15,7:30"), and the film's rating (R, PG-13, PG, or G). Include get and set methods for each; the setter for rating should check that the value is one of the four valid options...

  • Assighment. Creaung Java Classes with methods Note: If you have not yet completed this unit's Discussion,...

    Assighment. Creaung Java Classes with methods Note: If you have not yet completed this unit's Discussion, it is best to complete it before you begin this Assignment As studied in the Discussion, it is important to design a test plan prior to creating a class, as it will help reduce coding problems. In this unit's Assignment, you create, compile, and execute a class containing methods. Be sure to use best coding practices, such as creating a test plan, before you...

  • C++ Program 1. Create a class named BaseballGame that has fields for two team names and...

    C++ Program 1. Create a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Your application declares an array of 12 BaseballGame objects. Prompt the user for data for each object, and display all the values. Then pass each object to a method that displays the name of the winning team or “Tie” if the score is a tie. (main.cpp,...

  • In java How to get started; Create a class called Card. The card has three fields;...

    In java How to get started; Create a class called Card. The card has three fields; a value , a suit and a face. The card class has a constructor that takes three values for the three fields. Create a no-args constructor. The Card class has three get methods to return the values of each of the fields. The Card class has a toString( ) method. The Card class has a compareTo( ) method that uses the value of the...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    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...

  • Create a java class that implements BagInterface using singly linked data. Name this new class LinkedBag....

    Create a java class that implements BagInterface using singly linked data. Name this new class LinkedBag. Be sure to include a default constructor to initialize the private members of the class. Test that your code works properly. BagInterface includes the methods:  public int getCurrentSize(); public boolean isEmpty(); public boolean add(T newEntry); public T remove(); public boolean remove(T anEntry); public void clear(); public int getFrequencyOf(T anEntry); public boolean contains(T anEntry); public T[] toArray();

  • Write an ADT named circle in java containing the following. Include data: radius (double) Include methods:...

    Write an ADT named circle in java containing the following. Include data: radius (double) Include methods: A no-argument constructor A constructor that sets the data to passed values Getters and setters for each piece of data getArea (Math.PI * radius * radius … try using a Math method here) getDiameter (radius * 2) getCircumference (2 * Math.PI * radius) A toString( ) method to display the object data Include Javadoc comments for the class and every method, and generate the...

  • JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class....

    JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT