Answered step by step
Verified Expert Solution
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
TypeClass
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 : 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 addNumint num
This method should add the number to the TreeSet only if it is not divisible by and
Requirement : 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,
Createa main method with the menu as described in the sample Input andOutput.
Whenthe user selects option Addnumber,add the numberinto numSet.
Whenthe user selects option FindAverage,it should display the averageof the numbers of the numSet.If the set is empty, it should display "Theset is empty".
When the user selects option Exit,display the message "Thankyou for using the application" andterminate the program.
Option can take only values to
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started