Below is a definition for a Dumbbell class: public class Dumbbell { private double weight; // in pounds public Dumbbell() { weight = 1.0; } public Dumbbell(double w) { weight = w; } public void setWeight(double newWeight) { weight = newWeight; } public double getWeight() { return weight; } public lift() { System.out.println("You did 1 rep with the " + weight + " lb dumbbell."); } } Modify the setWeight method to check that the new weight parameter is between 1 and 50 pounds. If the new weight is less than 1 pound, set it to 1 pound instead. If the new weight is greater than 50 pounds, set it to 50 pounds instead. Show the modified method in your post. Add a second lift() method which takes an integer parameter signifying how many reps to do with the dumbbell. Print an appropriate message for the number of reps performed, similar to the message in the existing lift() method. If the number of reps is 20 or more, also print out the statement "Whew, what a workout!" afterward. If the number of reps entered is 0 or less, print out an appropriate error message instead. Show the new method in your post. Create a short main() method which creates two Dumbbell objects and calls a lift() method on each of them. The first Dumbbell should use the constructor and lift() method without parameters, and the second Dumbbell should use the constructor and lift() method with parameters (you create the lift() method with a parameter in step 2). Show this main method in your submission.
Below is a definition for a Dumbbell class: public class Dumbbell { private double weight; // in pounds public Dumbbell() { weight = 1.0; } public Dumbbell(double w) { weight = w; } public void setWeight(double newWeight) { weight = newWeight; } public double getWeight() { return weight; } public lift() { System.out.println("You did 1 rep with the " + weight + " lb dumbbell."); } } Modify the setWeight method to check that the new weight parameter is between 1 and 50 pounds. If the new weight is less than 1 pound, set it to 1 pound instead. If the new weight is greater than 50 pounds, set it to 50 pounds instead. Show the modified method in your post. Add a second lift() method which takes an integer parameter signifying how many reps to do with the dumbbell. Print an appropriate message for the number of reps performed, similar to the message in the existing lift() method. If the number of reps is 20 or more, also print out the statement "Whew, what a workout!" afterward. If the number of reps entered is 0 or less, print out an appropriate error message instead. Show the new method in your post. Create a short main() method which creates two Dumbbell objects and calls a lift() method on each of them. The first Dumbbell should use the constructor and lift() method without parameters, and the second Dumbbell should use the constructor and lift() method with parameters (you create the lift() method with a parameter in step 2). Show this main method in your submission.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Below is a definition for a Dumbbell class:
public class Dumbbell {
private double weight; // in pounds
public Dumbbell() {
weight = 1.0;
}
public Dumbbell(double w) {
weight = w;
}
public void setWeight(double newWeight) {
weight = newWeight;
}
public double getWeight() {
return weight;
}
public lift() {
System.out.println("You did 1 rep with the " + weight + " lb dumbbell.");
}
}
- Modify the setWeight method to check that the new weight parameter is between 1 and 50 pounds. If the new weight is less than 1 pound, set it to 1 pound instead. If the new weight is greater than 50 pounds, set it to 50 pounds instead. Show the modified method in your post.
- Add a second lift() method which takes an integer parameter signifying how many reps to do with the dumbbell. Print an appropriate message for the number of reps performed, similar to the message in the existing lift() method. If the number of reps is 20 or more, also print out the statement "Whew, what a workout!" afterward. If the number of reps entered is 0 or less, print out an appropriate error message instead. Show the new method in your post.
- Create a short main() method which creates two Dumbbell objects and calls a lift() method on each of them. The first Dumbbell should use the constructor and lift() method without parameters, and the second Dumbbell should use the constructor and lift() method with parameters (you create the lift() method with a parameter in step 2). Show this main method in your submission.
Expert Solution
Step 1: Overview
The Java program is given below:
Step by step
Solved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education