QuestionQuestion

MooseYogurt that has an instance String variable for the shopID number/name that uses a static variable called shopCount (that keeps track of all shops in a city) an instance variable for how many frozen yogurts are sold in the shop that day. In addition, there is a static variable that tracks the total number of frozen yogurts that are sold by all the shops and another static variable that specifies the cost per frozen yogurt.

Add the following methods:
A constructor that sets the shopID using the shopCount. The constructor should also set the number of yogurts sold by that stand to 0.
A method named justSold that increments the number of frozen yogurts sold by that shop by 1.
Another method to return the number of frozen yogurts sold by that shop.
A static method to set the cost per frozen yogurt.
A static method that returns the total number of frozen yogurts sold by all shops.
A static method that returns the total number of Moose Yogurts shops in a city.

Test your MooseYogurt by creating an array that stores at least five frozen yogurt shops that each sell some amount of frozen yogurts during the day. And print out the total yogurts sold, total sales, the number of shops and the top shop (in your tester class).

A sample screen dialog is given below. For this example, the cost of the frozen yogurt is set to $1.50.
Frozen Yogurt Sales:
Shop Sales
M1 14   // (means that MooseYogurt Shop M1 sold 14 frozen yogurts)
M2 10
M3 24
M4 20
M5 15
M6 30

Total frozen yogurts sold: 113
Total sales: $169.50
There are 6 Moose Yogurt shops.
Top shop today: M6.

Input
Create MooseYogurt class and then create MooseYogurt objects in the ShopDemo class.

Semantics
Create MooseYogurt objects, stored in an array, and manipulate them.

Output
The MooseYogurt objects after creating them and display their state and the state of all MooseYogurt shop objects.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class MooseYogurt {
   
    public static void main(String[] args) {
       /**
         * Test your MooseYogurt by creating an array that stores at
         * least five frozen yogurt shops that each sell some amount of
         * frozen yogurts during the day.
         */
       // the cost of the frozen yogurt is set to $1.50.
       MooseYogurt.setCost(1.5);
      
       // number of yogurts sold by each shop
       int[] sales = new int[] {14, 10, 24, 20, 15, 30};
       MooseYogurt [] shop = new MooseYogurt[sales.length];
       /***
         * iterate over array of shop
         */
       for (int i = 0; i < sales.length; i++) {
            shop[i] = new MooseYogurt();
            for (int j = 0; j < sales[i]; j++) {
                // sel yogurt
                shop[i].justSold();
            }
       }
      
       // pritn result
       System.out.println("Frozen Yogurt Sales: ");
       System.out.printf("%-6s%-6s\n", "Shop", "Sales");
       for (int i = 0; i < shop.length; i++) {
            MooseYogurt mooseYogurt = shop[i];...

By purchasing this solution you'll be able to access the following files:
Solution.java.

$15.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats