In this exercise, you will write a class that models a band booster and use your
ID: 3633096 • Letter: I
Question
In this exercise, you will write a class that models a band booster and use your class to update sales ofband candy.
1. Write the BandBooster class assuming a band booster object is described by two pieces of instance
data: name (a String) and boxesSold (an integer that represents the number of boxes of band candy
the booster has sold in the band fundraiser). The class should have the following methods:
• A constructor that has one parameter—a String containing the name of the band booster. The
constructor should set boxesSold to 0.
• A method getName that returns the name of the band booster (it has no parameters).
• A method updateSales that takes a single integer parameter representing the number of
additional boxes of candy sold. The method should add this number to boxesSold.
• A toString method that returns a string containing the name of the band booster and the
number of boxes of candy sold in a format similar to the following:
Joe: 16 boxes
2. Write a program that uses BandBooster objects to track the sales of 2 band boosters over 3 weeks.
Your program should do the following:
• Read in the names of the two band boosters and construct an object for each.
• Prompt for and read in the number of boxes sold by each booster for each of the three weeks.
Your prompts should include the booster’s name as stored in the BandBooster object. For
example,
Enter the number of boxes sold by Joe this week:
• For each member, after reading in the weekly sales, invoke the updateSales method to update
the total sales by that member.
• After reading the data, print the name and total sales for each member (you will implicitly use
the toString method here).
HERE'S THE CODE!!!! THE PROBLEM IS THAT THIS CODE KEEPS ON PRINTING ENTER NAME...IT DOESN'T LET THE USE ENTER, JUST KEEPS ON PRINTING ENTER NAME!!!
1)
import java.util.*;
public class SPATILBandBooster {
public static void main(String[] args) {
Scanner Keyboard = new Scanner(System.in);
String boosterName;
String boosterName1;
String num1;
int weeks;
Integer count = 0;
while (count < 3)
{
System.out.println("Enter Name: ");
boosterName = Keyboard.toString();
num1 = count.toString();
boosterName1 = boosterName.concat(num1);
BandBooster BandBooster = new BandBooster(boosterName);
}
System.out.println("Number of weeks: ");
weeks = Keyboard.nextInt();
for (int num = 1; num <= weeks; num++)
{
}
}
}
2)class BandBooster {
private String name1;
private int boxesSold;
public BandBooster(String name)
{
boxesSold = 0;
name1 = name;
}
public String getName()
{
return name1;
}
public void updateSales(int Boxes)
{
boxesSold = Boxes + boxesSold;
}
public String toString()
{
return (name1 + ": " + boxesSold + " boxes.");
}
}
additonal details :BandBooster BandBooster = new BandBooster(boosterName);
Explanation / Answer
try replace the wrong line by BandBooster BandBooster = new BandBooster(boosterName); but you should recover your while statement to make it work well This the Code after editing it but you still see wrong with while >> not work as well as it should be import java.util.*; public class SPATILBandBooster { public static void main(String[] args) { Scanner Keyboard = new Scanner(System.in); String boosterName; String boosterName1; String num1; int weeks; Integer count = 0; while (count < 3) { System.out.println("Enter Name: "); boosterName = Keyboard.toString(); num1 = count.toString(); boosterName1 = boosterName.concat(num1); BandBooster BandBooster = new BandBooster(boosterName); } System.out.println("Number of weeks: "); weeks = Keyboard.nextInt(); for (int num = 1; numRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.