Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Daniel is a Maths teacher. He often throws puzzles to his students to help them stay focused. One day he said, he will spell out

Daniel is a Maths teacher. He often throws puzzles to his students to help them stay focused. One day he said, he will spell out a set of numbers. The students should exclude all the numbers that are divisible by five and six and then calculate the average of the remaining numbers and tell him. Help them to implement the above task.
Implement the above scenario using a TreeSet.
Component Specification: NumAvg
Type(Class)
Attributes
Methods
Responsibilities
NumAvg
TreeSet numSet
Include the getter and setter method.
Note: The class and methods should be declared as public and all the attributes should be declared as private.
Requirement 1: Add number to the TreeSet.
As per this requirement, the system should be able to add a number to the TreeSet
Component Name
Type (Class)
Methods
Responsibilities
Add a number to the TreeSet
NumAvg
public void addNum(int num)
This method should add the number to the TreeSet only if it is not divisible by 5 and 6.
Requirement 2: Find the average of the numbers in the TreeSet.
As per this requirement, the system should be able to calculate the average of the numbers present in the TreeSet.
Component Specification: NumAvg
Component Name
Type (Class)
Methods
Responsibilities
Find the average of the numbers in the TreeSet.
NumAvg
public double calAvg()
This method is used to find the average of the numbers in the TreeSet.
In the UserInterface class,
1. Createa main method with the menu as described in the sample Input andOutput.
2. Whenthe user selects option 1.Addnumber,add the numberinto numSet.
3. Whenthe user selects option 2.FindAverage,it should display the averageof the numbers of the numSet.If the set is empty, it should display "Theset is empty".
4. When the user selects option 3.Exit,display the message "Thankyou for using the application" andterminate the program.
5.Option can take only values 1 to 3.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+38-1 Describe the physiological factors that produce hunger.

Answered: 1 week ago