Question: For Java, write some classes. 1. First class ~ Food - this class should have a reference to the second class 'LunchTime' named menu and

For Java, write some classes.

1. First class ~ Food

- this class should have a reference to the second class 'LunchTime' named menu and a bool called 'drink' that shtores if they have a drink each day. and also a reference to an array(int) named numberOfMeals where each member of the array corresponds to the week in the term (essentially meals they used for a week) [you can also add an integer named semesterLength thats equal to 12.]

-Write a constructor and methods for the this:

-constructor with a bool parameter that records if the instance fir a drink(also have the constructor assign numberOfMeals to an array it instantiates)

For methods ~

setLunchTime - has a single LunchTime parameter, should be made an alias of the parater and doesn't return anything

aDrink - no parameters, should return value of drink

foodPerWeek - no parameters, it returns a double equal to average number of food per week the instance ate

eatFood - has an int parameter for the current week(index numberOfMeals) have this increment the entry at the index and not return anything

allowAccess - has one int parameter representing the current week(like before, index numberOfMeals) return true if entry index is less than plan's max per week, if else return false

Class #2 - LunchTime

-It has a reference array of Food named children, an integer named maxLunch that stores the number of times the child ate lunch per week on the plan, and a double lunch_price that stores the average price of lunch (have it set to $4.95)

-For the constructor, it should have a single integer parameter that initializes maxLunch

-For the methods, setChild has a single Food[] parameter(child should be made an alias of the parater and without returning anything)

- getLunchLimit with no parameters, should return the value of maxLunch

-avgDrinkCost with no parameters, it counts the current number of drinks the children have and the sume of their average number of lunches eaten per week (method returns a double equal to the sum multiplied by the average lunch cost and then divided by the number of drinks students have(average cost of lunch per week per student with a drink)

-avgCost with no parameters, it counts the current number of children with a drink and the sum of those children average number of lunches per week. this method returns a double equal to the sum multiplied by the average lunch cost divided by the number of children with a drink.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!