Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**IN JAVA** Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Notes: Assume that the classes listed in the

**IN JAVA**

image text in transcribedimage text in transcribed

Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Notes: Assume that the classes listed in the Java Quick Reference have been imported where appropriate Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. 1. This question involves managing music lessons at a music school. Lessons are defined by the following Lesson class. public class Lesson { /** Returns the type of the lesson */ public String getType() 1 /* implementation not shown */ 1 /** Returns the cost of the lesson */ public double getcost() { /* implementation not shown / /** Sets the cost of the lesson to newCost */ public void setCost(double newcost) { /* implementation not shown */ } /** Returns true if the lesson signup occurred during the early registration period and returns false otherwise public boolean is RegEarly { /* implementation not shown */ } // There may be instance variables, constructors, and methods that are not shown. > Information about a music school is stored in a Musicschool object, which contains a list of the lessons that students have signed up for at the school. You will write two methods of the Musicschool class. public class Musicschool { /** A list containing information about lessons signed up for at the school * Guaranteed not to be null and to contain only non-null entries private ArrayList lessonList; /** Updates the cost for all lessons, as described in part (a) / public void updateCosts(double piano, double voice, double reg) /* to be implemented in part (a) */ } /** Updates the cost of a randomly selected piano lesson by a given discount and returns the * updated cost, as described in part (b) Precondition: At least one lesson meets the eligibility requirements and the discount is less than the cost of the lesson. public double getDiscountedLessonCost[double discount) { /* to be implemented in part (b) */ // There may be instance variables, constructors, and methods that are not shown. } (a) Write the Musicschool method updatecosts. Once a year, the school updates the costs of lessons based on the following rules The cost of all "piano lessons is increased by the value of the parameter piano. The cost of all "voice" lessons is increased by the value of the parameter voice The cost of all other types of lessons is increased by the value of the parameter reg. For example, assume that chelseaSchool has been declared as a Music School object and that lesson, lesson2, lesson3, lesson, lessons, and lesson are properly declared and initialized Lesson objects in lessonList. The following table shows the cost of lessons before and after the method call chelseaschool.updatecosts(2.0, 4.0, 1.0) Lesson Cost Before the Lesson Cost After the Lesson Object Lesson Type Method Call Method Call lesson " guitar" 20.0 21.0 10.0 12.0 lesson2 lesson 15.0 17.0 "piano "piano "voice" "cello" lesson 35.0 39.0 25.0 lessons lessons 26.0 22.0 "piano 20.0 Complete method updateCoats /** Updates the cost for all lessons, as described in part (a) / public void updateCosts (double piano, double voice, double reg) (b) Write the Musicschool method get DiscountedLessonCost. Once a month, the music school offers a discount on a randomly selected, eligible lesson. A lesson is eligible for the discount if the type of lesson is "piano" and the lesson was signed up for during the early a registration period. Each eligible lesson must have an equal chance of being selected The method updates the cost of the selected lesson and returns the updated lesson cost, as described in the following example. Assume that chelseaSchool has been declared as a Musicschool object and contains the following Lesson objects. Lesson is Reglarly Lesson Type Lesson Cost Object Return value 20.0 true 10.0 false lesson: lesson 2 lesson) lesson lessons 15.0 true "guitar "piano" "piano "voice "cello "piano 35.0 false 25.0 false lessons 20.0 true There are two eligible lessons, lessons and lesson. Either could be selected by the call chelseaschool.getDiscountedLessoncost(4.0). If lesson3 were selected, its cost would be updated to 11.0 and the value 11.0 would be returned. If lesson were selected, its cost would be updated to 16.0 and the value 16.0 would be returned. Complete method getDiscountedLessoncoat /** Updates the cost of a randomly selected piano lesson by a given discount and returns the updated cost, as described in part (b) * Precondition: At least one lesson meets the eligibility requirements and the discount is less than the cost of the lesson. */ public double getDiscountedLessonCost(double discount) (c) The programmer would like to add a method called get InstructorwithMostLessons, which returns the name of the instructor who is currently teaching the most lessons. Write a description of how you would change the lesson and Musicschool classes in order to support this modification Make sure to include the following in your response. Write the method header for the getInstructor with HostLessons method. Identify any new or modified variables, constructors, or methods aside from the get InstructorWithMostLessons method. Do not write the program code for this change Describe for each new or revised variable, constructor, or method, how it would change or be implemented, including visibility and type. You do not need to describe the implementation of the getInstructorWithMostLessons method. Do not write the program code for this change

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

Understand the importance of organizational change.

Answered: 1 week ago