Question
A class is to be written that models a school fundraising project and use your class to update sales of chocolates. Write the ChocolateDrive class
A class is to be written that models a school fundraising project and use your class to update sales of chocolates. Write the ChocolateDrive class assuming a chocolate fundraiser object is described by two pieces of instance data: name (a String) and boxesSold (an integer that represents the number of boxes of chocolate the fundraiser has sold). The class should have the following methods:
a. A constructor that has one parametera String containing the name of the fundraiser. The constructor should set boxesSold to 0.
b. A method getName that returns the name of the chocolate fundraiser (it has no parameters).
c. A method updateSales that takes a single integer parameter representing the number of additional boxes of chocolate sold. The method should add this number to boxesSold.
d. A to String method that returns a string containing the name of the fundraiser and the number of boxes of chocolate sold in a format similar to the following:
Joe: 16 boxes
A program is to be written that uses ChocolateDrive objects to track the sales of 2 fundraisers over 3 weeks. Your program should do the following:
e. Read in the names of the two fundraisers and construct an object for each. f. Prompt for and read in the number of boxes sold by each fundraiser for each of the three weeks. Your prompts should include the fundraiser's name as stored in the ChocolateDrive object. For example,
i. Enter the number of boxes sold by Joe this week:
g. For each member, after reading in the weekly sales, invoke the updateSales method to update the total sales by that member.
h. After reading the data, print the name and total sales for each member (you will use the toString method here).
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