Chapter 5: The Goodies Co. – Next step

The Goodies Company Project

vendingmachines

Designing and Implementing – Phase 1:
1. Use your questions and answers as a guide to define the signature of every class’ method.
2. Draw a UML class diagram for your entire application. Make sure you follow the rules for UML.
NOTE: You can use google doc drawing or just a word doc.
.
goodies-Class-Digram-phase-2-2
.
.
UMLBasics-arrows
.
.
Here is the link to a UML builder you used before.
www.umletino.com

Using your Design/UML, implement the Business Operations application for the business owner/manager/bookkeeper/accountant to operate the business.

Day 3: The user interface
Write a program (main) that displays multiple menus.
Example of a simplified session to start your code:

Welcome to Goodies Vending System
1. Business Operation
2. Customer
3. Exit
What is your choice? 1

Business Operations
1. View Inventory
2. Re-stock
3. blah blah …
4. blah blah …
5. Back to the main menu
6. Exit Goodies Vending System
What is your choice? 5

Welcome to Goodies Vending System
1. Business Operation
2. Customer
3. Exit
What is your choice? 2

Welcome to Goodies Vending Machine
Here are your choices:
1. Drinks
2. Drygoods
3. Frozen delights
4. blah blah …
5. Back to the main menu
6. Done with purchases
7. Exit Goodies Vending System
1 –> drinks menu should come up
Prompt the buyer for more purchases or to go back to the main menu.

What is your choice? 5

Your total is $22.75
Bye! See you soon.
It was a pleasure to serve you!

What is next?
A modified Menu:
1. Start the company’s initial state. That includes inventory with the cost associated with the purchases of the products. This feature enables the user to print the table below with the current inventory.
NOTE: display all information in well-aligned columns. Use “printf”.

  1. Updates to the products, quantities, cost and the sale price.
  2. Closing of the business cycle by producing a report with all needed information.
  3. If you need more information from the client, add the questions to your list.
  4. Test your implementation with the client’s data.
  5. Let your client use your implementation.
  6. Make changes to your implementation based on your client’s comments and suggestions.

Check edmodo for the due dates. WARNING: there are no soft due dates for this project. All due dates are hard and penalties will be applied.

Find below some basic raw data to start with but it is not limited to.

This menu will be used by the manager/owner/business operator

Drinks 
         Quantity Available  Cost/case(45) $  Sale Price $
1. Sunkist            45            16         1.25
2. Coca Cola          45            18         1.25
3. Brisk              45            17         1.25
5. Sprite             45            17         1.25
6. Ginger Ale         45            21         1.25
7. Dr. Pepper         45            20         1.25
8. Capri Sun          45            15         1.25
9. Water              45            22         1.00

Snacks 
         Quantity Available  Cost/case(45) $  Sale Price $
1. Chips              45            25         0.75          
2. Pop corn           45            22         0.75         
3. Pop Corners        45            22         0.75     
4. Veggie Sticks      45            21         0.75     
5. Rice Krispies      45            20         0.50     
6. Cookies            45            36         0.75         
7. Granola Bars       45            40         0.50 
8. Fruit Snacks       45            28         0.50 
9. Snack Bars         45            41         0.50

NOTE: Keep all this information as raw data in a text file.
Raw data text file should look like this:
snacks
Chips,45,25,0.75
Popcorn,45,22,0.75
Pop Corners,45,22,0.75
Cheeze it,45,18,0.75
Gold Fish,45,18,0.75
Oreo Cookies,45,30,0.75
Fruit Snack,45,15,0.25
Trail Mix,45,22,0.50
Nutrigrain,45,31,0.50
Peanut Bar,45,16,0.50
drinks
Coke,45,18,1.25
Sprite,45,17,1.25
Sunkist,45,16,1.25
Brisk,45,17,1.25
Ginger Ale,45,21,1.25
Water,45,22,1.00
Capri Sun,45,15,0.75
else
Ice cream,45,20,1.00
Klondike Bars,45,15,1.25
Italian Ice,45,10,1.25
Ice pop,45,16,0.25
end

Warning: NO SPACES should be used to separate the data fields and the commas.

I attached two files with java code to read and write text files. However, there are other options you can use.

Q. What is the public interface of a class?
A. The public interface of a class is a document with the name of each method, the description of the method, and the method’s pre-conditions and post-conditions.

This menu could be typical for a menu for purchasing snacks and drinks

Drinks 
                 Sale Price $
1. Sunkist            1.25
2. Coca Cola          1.25
3. Brisk              1.25
5. Sprite             1.25
6. Ginger Ale         1.25
7. Dr. Pepper         1.25
8. Capri Sun          1.25
9. Water              1.00

Snacks 
                  Sale Price $
1. Chips              0.75          
2. Pop corn           0.75         
3. Pop Corners        0.75     
4. Veggie Sticks      0.75     
5. Rice Krispies      0.50     
6. Cookies            0.75         
7. Granola Bars       0.50 
8. Fruit Snacks       0.50 
9. Snack Bars         0.50

WriteToTxtFile

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
// http://www.homeandlearn.co.uk/java/write_to_textfile.html
/**
 * Write a description of class WriteToTxtFile here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class WriteToTxtFile
{
    public static void main(String [] args)
    {
        String myFile = "RawData.txt";
        try{
            FileWriter write = new FileWriter( myFile);
            PrintWriter print_line = new PrintWriter(write);
            print_line.printf("%s" + "%n", "Testing write to a file");
           
        print_line.close();
        }
        catch (IOException e) { System.out.println("It doesn't work");
        
        
        }
    }
}

[collapse]
ScannerReadFile

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
 
public class ScannerReadFile {
 
    public static void main(String[] args) {
 
        // Location of file to read
        File file = new File("data.txt");
 
        try {
 
            Scanner scanner = new Scanner(file);
 
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                System.out.println(line);
            }
            scanner.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
 
    }
}


[collapse]

Standard Libraries
printf short version
printf resource