code in java
In this program we are going to help a user track their snacks.
This program requires two classes. The Hobby class cannot have any
interaction with the user. The HobbyDriver must handle all of the
user interactions and will use the methods provided in Hobby to
allow the user to determine if the hobby is valid.
Hobby cannot print or read input from the user. HobbyDriver
cannot do validations, it must react to the validations from Hobby.
Failure to follow either of these will result in a 10 point
deduction.
Hobby
The Hobby class will have the following instance variables:
String name
int minutesRequired
String type
You should provide a getter and setter for each member variable.
You also need to provide two constructors, a no argument and a 3
argument. You must provide a toString method for this class.
Default values for the no argument constructor should be name
= "Woodworking", minutes = 180, type = "Crafting".
Validations must be done in this class. Acceptable values are as
follows:
name – cannot be blank
minutes – greater than 0
type – crafting, sewing, fishing, gaming
HobbyDriver
This class will handle all of the user interaction. This class
will get the information from the user and be responsible for
displaying the results to the user.
You should create an array of three hobbies. The number of
hobbies must be controller with a constant. Create a method that
allows the user to enter hobbies. They must be entered in the order
of name, minutes and type. You should use the validations from
Hobby to ensure valid entries. After the user has entered their
hobbies, call a method to display the hobbies.
All member variables must be private.
You are only allowed to use the keyword static for the
main method and the constant. The constant can be
public.
Class and method comments are not required.
Sample output:
Please enter the name for the hobby
Hobby name cannot be blank.
Please enter the name for the hobby
Wood turning
Please enter the time to spend on Wood turning, in minutes
-1
Time spent must be greater than 0.
Please enter the time to spend on Wood turning, in minutes
60
Please enter the type of hobby for Wood turning
turning
The hobby type must be 'Crafting', 'Sewing', 'Fishing' or
'Gaming'
Please enter the type of hobby for Wood turning
crafting
Please enter the name for the hobby
Puzzle solving
Please enter the time to spend on Puzzle solving, in minutes
45
Please enter the type of hobby for Puzzle solving
gaming
Please enter the name for the hobby
Bass fishing
Please enter the time to spend on Bass fishing, in minutes
120
Please enter the type of hobby for Bass fishing
fishing
Hobby: name = Wood turning, minutes = 60, type = 'crafting
Hobby: name = Puzzle solving, minutes = 45, type = 'gaming
Hobby: name = Bass fishing, minutes = 120, type = 'fishing
code in java In this program we are going to help a user track their snacks. This program requires two classes. The Hobb
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
code in java In this program we are going to help a user track their snacks. This program requires two classes. The Hobb
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!