Project 2: FrozenYogurt class

Objectives:

Getting Help

This project sometimes takes students many, many hours. Please promise yourself that you will reach out to the CS Tutors or your instructor for help if you have already spent 10 or more hours on the project or if you have been stuck for more than 1 hour.

Description

For this project, you get to design and write a FrozenYogurt class that represents a frozen yogurt dessert. You also get to write FrozenYogurtDriver class, a driver class for your FrozenYogurt class.

FrozenYogurt class

Design and write your FrozenYogurt class to store the following:

Additionally, include both a constructor without any parameters and one with parameters for the name, price, base flavor and topping (in that order). For the constructor without parameters, set the Strings to an empty string and the price to 0.0. Include appropriate accessor and mutator methods (and label them with comments including the terms "accessor" or "mutator"). So that the test cases compile, name the accessor methods:

Additionally, name the mutator methods:

Note, a single letter not capitalized will prevent a test case from compiling and running correctly. Double check these method names in your code.

Include, appropriately, the this keyword in your code. Do not use it when it is not required. You may need to create a situation where it is required.

Additionally, include a method named description() that returns a String that describes each of the four fields for the class. Format it as shown at the bottom of the examples below. Note, there should be no parameters to description().

Lastly, write your own custom method with either 1) one or more parameters, 2) a return value or 3) both parameter(s) and a return value.

The role of the FrozenYogurt class is to store the attributes of a frozen yogurt dessert. It could be used to store those values in an interactive session with a user at the keyboard or in a batch environment where other code is just setting values and using it (with no user at the keyboard). Consequently, your FrozenYogurt class should not use a Scanner object at all. Furthermore, you should not use System.out.print() (nor System.out.println()) statements in your FrozenYogurt class. Your Scanner object and calls to System.out.print() and System.out.println() should all be in the FrozenYogurtDriver class.

FrozenYogurtDriver class

Design and write a FrozenYogurtDriver class to be a driver for your FrozenYogurt class. Have your driver class welcome the user. Additionally, have the driver class request input to be used to populate two different FrozenYogurt objects then call each of the object's description() method. Additionally, call the custom method that you added on each object. If you want to get additional input from the user (that codePost was not expecting), be sure to do that after displaying everything that’s in the examples (thereby passing the tests). Otherwise, your code will stall at that point in the code and time out. To simplify your code, you can assume that all strings for this project (but not later projects) will be just one word.

Each of the methods (which includes your constructors) in your FrozenYogurt class will be tested using unit tests in codePost. Additionally, the output of your entire program will be tested with various inputs.

codePost does not support the package statement. If your IDE inserted one, I configured codePost to automatically remove it.

Examples

Note, user input is in bold face blue and the text that is underlined is required for the test cases.

Example A

Welcome to the Frozen Yogurt Selector

Please enter the name of the first frozen yogurt: Chocolatey
You entered: Chocolatey
Please enter the name of the second frozen yogurt: SassyStrawberry
You entered: SassyStrawberry
Please enter the price for the Chocolatey: 4.99
You entered: 4.99
Please enter the price for the SassyStrawberry: 3.99
You entered: 3.99
Please enter the base yogurt flavor for Chocolatey: chocolate
You entered: chocolate
Please enter the base yogurt flavor for SassyStrawberry: vanilla
You entered: vanilla
Please enter the topping to add to Chocolatey: cocoa
You entered: cocoa
Please enter the topping to add to SassyStrawberry: strawberries
You entered: strawberries
Frozen Yogurt : Chocolatey
Price         : $4.99
Yogurt        : chocolate
Topping       : cocoa

Frozen Yogurt : SassyStrawberry
Price         : $3.99
Yogurt        : vanilla
Topping       : strawberries

Thank you!

Example B

Welcome to the Frozen Yogurt Selector

Please enter the name of the first frozen yogurt: VanMango
You entered: VanMango
Please enter the name of the second frozen yogurt: RockyRoad
You entered: RockyRoad
Please enter the price for the VanMango: 5.25
You entered: 5.25
Please enter the price for the RockyRoad: 3.89
You entered: 3.89
Please enter the base yogurt flavor for VanMango: vanilla
You entered: vanilla
Please enter the base yogurt flavor for RockyRoad: chocolate
You entered: chocolate
Please enter the topping to add to VanMango: Mango
You entered: Mango
Please enter the topping to add to RockyRoad: Marshmallows
You entered: Marshmallows
Frozen Yogurt : VanMango
Price         : $5.25
Yogurt        : vanilla
Topping       : Mango

Frozen Yogurt : RockyRoad
Price         : $3.89
Yogurt        : chocolate
Topping       : Marshmallows

Thank you!

Rubric

Points      Item
----------  --------------------------------------------------------------
_____ / 10  Style
            + Code is indented correctly
            + Methods should be no longer than 1 page
            + Documentation: (written for another software developer)
              * All source code files include header block with description, author, version, etc.
              * Comments before each method
              * All non-trivial variables are commented
              * Comments included before major portions of code
_____ /     Compiles (max of 50% if it doesn't compile)
_____ /  8  Constructor-No Parameters and Accessor Methods Test
_____ / 13  Constructor and Accessors Test
_____ / 20  Mutators and Accessors Test
_____ / 13  description() Test
_____ / 21  Input / Output Tests (including creating and using a FrozenYogurt object) 
_____ /  5  this (Keyword) Test
_____ /  8  Custom method (designed and called)
_____ /  2  Completed rubric (estimates for each line including hours spent, and signing your name to affirm it's your own work)

_____ /100  Total


_____  Approximate number of hours spent

I, (REPLACE WITH YOUR FULL NAME), affirm that the code that I submitted is my own work and that I did not receive help that was not authorized by the instructor.

Copy and paste the above rubric into a rubric-FrozenYogurt.txt file (not a .docx, .doc nor .rtf file). Think of this as a checklist to ensure that you receive the maximum points possible. For each grade item, fill in your estimate for the grade you deserve. Additionally, include your estimate of how many hours your spent. Lastly, replace, "(REPLACE WITH YOUR FULL NAME)" with your full name to indicate that what you are submitting is entirely your own work.

Submission

The submission process has two parts:

  1. codePost

    Submit your FrozenYogurt class and your FrozenYogurtDriver class to codePost.io. To register for a free codePost account, please follow these instructions. You can submit to codePost multiple times if you want. Only your last submission will be graded. Watch this short video for a demonstration of submitting an assignment and reviewing the results:
    YouTube video: codePost: Submission and Checking Results Thumbnail

  2. CougarVIEW

    Submit your rubric-FrozenYogurt.txt to the appropriate Assignment tab/folder in CougarVIEW. This is required to receive detailed graded feedback on your project. If you resubmit your rubric, this will effectively replace your previous submission.

Helps

  1. Only One Scanner Object:
    You should only have one Scanner object (per stream) per program. A Scanner object will read ahead to parse the stream and therefore may read more than what it returns. If a second object is created, then part of the input may only be known to the first Scanner object. The solution is to only have one "new Scanner( System.in )" in your program.
  2. Only 1 class per file:
    While it is possible to put multiple classes in a single file, just include 1 per file. Additionally, the file must be named exactly the same as the name of the class, with .java added onto the end.
  3. codePost:
    1. To view the automatic feedback (including which tests passed and which ones failed) in codePost, you can click on “Upload assignment” at the main landing page, https://codepost.io/student/CPSC%201302/Fall%202022/. This will pop-up a warning about replacing files. You can ignore that and just click on "Continue" if you're not submitted new files. Then, click on the "Tests" tab and then the on the plus sign to the left of the test name. This will show you a simple congratulatory message if all tests passed or the results of why it did not pass.
    2. If you're trying to figure out what's wrong with your Project 2 submission in codePost, look in the "_tests.txt" file. In codePost, click on "_tests.txt" link on the left, just above the links to your source code files. It will have any compilation errors in that file.
    3. I've seen a bug in codePost where a student resubmitted an assignment and then none of the tests passed. The automatic feedback for all the tests reports RunError.JsonParseError. If that happens to you, just resubmit them. Sorry about that.
    4. When you see an error with something like:
      _test54735.java:55: error: constructor FrozenYogurt in class FrozenYogurt cannot be applied to given types;
              FrozenYogurt frozYogurt = new FrozenYogurt( randName, randPrice, randFlavor, randTopping );
                                                ^
        required: no arguments
        found: String,double,String,String
        reason: actual and formal argument lists differ in length
      
      or
      [codePost Test] ConstructorAndAccessorsTest:42: error: no suitable constructor found for FrozenYogurt(String,double,String,String)
      FrozenYogurt fyObj = new FrozenYogurt( randName, randPrice, randFlavor, randTopping );
                                        ^
      constructor FrozenYogurt.FrozenYogurt() is not applicable
      (actual and formal argument lists differ in length)
      constructor FrozenYogurt.FrozenYogurt(<varies by submission>) is not applicable
      (actual and formal argument lists differ in length)
      This means that the following code in one of the tests: FrozenYogurt fyObj = new FrozenYogurt( randName, randPrice, randFlavor, randTopping ); was not able to compile because the compiler could not find a constructor in your code that takes a String, double, String and a String as arguments (in that order). The solution is to write such a constructor.
      Note, you will get a similar error message if you do not have another constructor that does not take any arguments as well.