SlideShare a Scribd company logo
1 of 6
Project 3: Frozen Yogurt with Mix-ins
Assignment
For this project, you get to build off of the FrozenYogurt class from Project 2 and exercise using
loops in Java! A very common application of loops is input validation. You will get to do that in
this project. Additionally, you get to use either a StringBuilder or StringBuffer object to store
multiple toppings in a FrozenYogurt object.
FrozenYogurt class
For the FrozenYogurt class make the following changes to that class:
(Driver class will be separate)
1.Change the instance variable for the topping to be either a StringBuilder or StringBuffer object
to appropriately support a comma-separated list of toppings (instead of just a single topping)
2.Change the setPrice method so that it returns a String. If the new price is negative, do not
update the price and return a String with the following value:
ALERT: Unable to set <name>'s price to <price> (negative values are not allowed)
Where <name> is the name of the frozen yogurt and <price> is the parameter's value. If the price
is 100.0 or greater, do not update the price and return a String with the following value:
ALERT: Unable to set <name>'s price to <price> (value is too high (>=100.00))
Otherwise, return an empty string.
3.Change setYogurtFlavor method so that it returns a String. If the new flavor is not "chocolate"
nor "vanilla", do not update the base flavor and return a String with the following value:
ALERT: <new yogurt flavor> is not one of the valid yogurt flavors (chocolate or vanilla)!
Where <new yogurt flavor> is the value of the parameter. If the new flavor is valid, then return
an empty string.
4.Add an addTopping method that take a String as a parameter. If the instance variable already
has a topping, then separate the previous value and the new value with ", ". Otherwise, just use
the new topping as the value (without a ","). For each additional topping added, add $0.49 to the
price.
import java.util.Scanner;
public class FrozenYogurt{
//private instance variables
private String name;
private double price;
private String flavor;
private String topping;
//constructor with no parameters
public FrozenYogurt(){
this.name = "";
this.price = 0.0;
this.flavor = "";
this.topping = "";
}
// constructor with parameters
public FrozenYogurt(String name, double price, String flavor, String topping){
this.name = name;
this.price = price;
this.flavor = flavor;
this.topping = topping;
}
// mutator methods
public void setName(String name){
this.name = name;
}
public void setPrice(double price){
this.price = price;
}
public void setYogurtFlavor(String flavor){
this.flavor = flavor;
}
public void setTopping(String topping){
this.topping = topping;
}
//Accessor methods
public String getName(){
return name;
}
public double getPrice(){
return price;
}
public String getYogurtFlavor(){
return flavor;
}
public String getTopping(){
return topping;
}
//toString method
public String toString(){
return "Frozen Yogurt: " + name + "nPrice: $" + price + "nYogurt: " + flavor + "nToppping: "
+ topping + "n";
}
//User inputs
public String valueEntered(String s){
return "You entered: " + s + "n";
}
}
//driver class
import java.util.Scanner;
public class FrozenYogurtDriver
{
public static void main(String[] args) {
//Scanner class
Scanner sc = new Scanner(System.in);
//object creation from FrozenYogurt
FrozenYogurt froyo1 = new FrozenYogurt();
FrozenYogurt froyo2 = new FrozenYogurt();
System.out.println("Welcome to the Frozen Yogurt Selector");
//User inputs for object
System.out.print("Please enter the name of the first frozen yogurt: ");
froyo1.setName(sc.nextLine());
System.out.println(froyo1.valueEntered(froyo1.getName()));
System.out.print("Please enter the name of the second frozen yogurt: ");
froyo2.setName(sc.nextLine());
System.out.println(froyo2.valueEntered(froyo2.getName()));
//User inputs for prices
System.out.print("Please enter the price for the "+ froyo1.getName() + ": ");
froyo1.setPrice(Double.parseDouble(sc.nextLine()));
System.out.println(froyo1.valueEntered(String.valueOf(froyo1.getPrice())));
System.out.print("Please enter the price for the "+ froyo2.getName() + ": ");
froyo2.setPrice(Double.parseDouble(sc.nextLine()));
System.out.println(froyo2.valueEntered(String.valueOf(froyo2.getPrice())));
//User inputs for flavors
System.out.print("Please enter the base yogurt flavor for " + froyo1.getName() +": ");
froyo1.setYogurtFlavor(sc.nextLine());
System.out.println(froyo1.valueEntered(froyo1.getYogurtFlavor()));
System.out.print("Please enter the base yogurt flavor for " + froyo2.getName() +": ");
froyo2.setYogurtFlavor(sc.nextLine());
System.out.println(froyo2.valueEntered(froyo2.getYogurtFlavor()));
//User inputs for toppings
System.out.print("Please enter the topping to add to " + froyo1.getName() +": ");
froyo1.setTopping(sc.nextLine());
System.out.println(froyo1.valueEntered(froyo1.getTopping()));
System.out.print("Please enter topping to add to " + froyo2.getName() +": ");
froyo2.setTopping(sc.nextLine());
System.out.println(froyo2.valueEntered(froyo2.getTopping()));
//display toSting
System.out.println(froyo1);
System.out.println(froyo2);
//Final message
System.out.print("Thank you!");
}
}

More Related Content

Similar to Project 3- Frozen Yogurt with Mix-ins Assignment For this project- you.docx

These are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdfThese are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdf
udit652068
 
To change this license header, choose License Headers in Pr.docx
To change this license header, choose License Headers in Pr.docxTo change this license header, choose License Headers in Pr.docx
To change this license header, choose License Headers in Pr.docx
gertrudebellgrove
 
To change this license header, choose License Headers in Pr.docx
  To change this license header, choose License Headers in Pr.docx  To change this license header, choose License Headers in Pr.docx
To change this license header, choose License Headers in Pr.docx
ShiraPrater50
 
Hello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdfHello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdf
fedosys
 
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdfSuggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
ssuser58be4b1
 
Here is the assignment5.java file -You are required, but not limi.pdf
Here is the assignment5.java file -You are required, but not limi.pdfHere is the assignment5.java file -You are required, but not limi.pdf
Here is the assignment5.java file -You are required, but not limi.pdf
mallik3000
 
Write a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfWrite a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdf
eyebolloptics
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
 
Design patterns in the 21st Century
Design patterns in the 21st CenturyDesign patterns in the 21st Century
Design patterns in the 21st Century
Samir Talwar
 
Can someone help me with this code When I run it, it stops after th.pdf
Can someone help me with this code When I run it, it stops after th.pdfCan someone help me with this code When I run it, it stops after th.pdf
Can someone help me with this code When I run it, it stops after th.pdf
Amansupan
 
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdfdatabase propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
fashiionbeutycare
 
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxcodeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
monicafrancis71118
 
Hello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdfHello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdf
pristiegee
 
How do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdfHow do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdf
forwardcom41
 
29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf
arishaenterprises12
 

Similar to Project 3- Frozen Yogurt with Mix-ins Assignment For this project- you.docx (17)

These are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdfThese are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdf
 
To change this license header, choose License Headers in Pr.docx
To change this license header, choose License Headers in Pr.docxTo change this license header, choose License Headers in Pr.docx
To change this license header, choose License Headers in Pr.docx
 
To change this license header, choose License Headers in Pr.docx
  To change this license header, choose License Headers in Pr.docx  To change this license header, choose License Headers in Pr.docx
To change this license header, choose License Headers in Pr.docx
 
Hello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdfHello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdf
 
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdfSuggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
 
Here is the assignment5.java file -You are required, but not limi.pdf
Here is the assignment5.java file -You are required, but not limi.pdfHere is the assignment5.java file -You are required, but not limi.pdf
Here is the assignment5.java file -You are required, but not limi.pdf
 
Write a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfWrite a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdf
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
Design patterns in the 21st Century
Design patterns in the 21st CenturyDesign patterns in the 21st Century
Design patterns in the 21st Century
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Can someone help me with this code When I run it, it stops after th.pdf
Can someone help me with this code When I run it, it stops after th.pdfCan someone help me with this code When I run it, it stops after th.pdf
Can someone help me with this code When I run it, it stops after th.pdf
 
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdfdatabase propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
 
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxcodeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
 
Hello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdfHello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdf
 
How do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdfHow do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdf
 
Computer programming 2 -lesson 4
Computer programming 2  -lesson 4Computer programming 2  -lesson 4
Computer programming 2 -lesson 4
 
29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf
 

More from EdwardEkRChapmann

Project Scope Statement for the MXE Project Introduction - The purpo.docx
Project Scope Statement for the MXE Project   Introduction - The purpo.docxProject Scope Statement for the MXE Project   Introduction - The purpo.docx
Project Scope Statement for the MXE Project Introduction - The purpo.docx
EdwardEkRChapmann
 
Problem 4-45 (LO- 4) Nell and Kirby are in the process of negotiating.docx
Problem 4-45 (LO- 4) Nell and Kirby are in the process of negotiating.docxProblem 4-45 (LO- 4) Nell and Kirby are in the process of negotiating.docx
Problem 4-45 (LO- 4) Nell and Kirby are in the process of negotiating.docx
EdwardEkRChapmann
 

More from EdwardEkRChapmann (20)

Q-5 Peyon Recaves 10-000 as a Gift FRem Huver her Mothen and She waxts.docx
Q-5 Peyon Recaves 10-000 as a Gift FRem Huver her Mothen and She waxts.docxQ-5 Peyon Recaves 10-000 as a Gift FRem Huver her Mothen and She waxts.docx
Q-5 Peyon Recaves 10-000 as a Gift FRem Huver her Mothen and She waxts.docx
 
Q- No-01 Kedzie Kord Company reported market price of its share as $50.docx
Q- No-01 Kedzie Kord Company reported market price of its share as $50.docxQ- No-01 Kedzie Kord Company reported market price of its share as $50.docx
Q- No-01 Kedzie Kord Company reported market price of its share as $50.docx
 
Q- (i1) Quinn Age is invests 20-000 in a Sey fund Contract and makes A.docx
Q- (i1) Quinn Age is invests 20-000 in a Sey fund Contract and makes A.docxQ- (i1) Quinn Age is invests 20-000 in a Sey fund Contract and makes A.docx
Q- (i1) Quinn Age is invests 20-000 in a Sey fund Contract and makes A.docx
 
Q!-(18) Edmond an ins agent meebs lelly who wants to purchese a whele.docx
Q!-(18) Edmond an ins agent meebs lelly who wants to purchese a whele.docxQ!-(18) Edmond an ins agent meebs lelly who wants to purchese a whele.docx
Q!-(18) Edmond an ins agent meebs lelly who wants to purchese a whele.docx
 
Python Key Value Store Design Properly implement an application with a.docx
Python Key Value Store Design Properly implement an application with a.docxPython Key Value Store Design Properly implement an application with a.docx
Python Key Value Store Design Properly implement an application with a.docx
 
Puestion 6 if itolmiti 3) Trie aj falun Question 7(4 soints) 11- mupat.docx
Puestion 6 if itolmiti 3) Trie aj falun Question 7(4 soints) 11- mupat.docxPuestion 6 if itolmiti 3) Trie aj falun Question 7(4 soints) 11- mupat.docx
Puestion 6 if itolmiti 3) Trie aj falun Question 7(4 soints) 11- mupat.docx
 
public class ExampleCode2 { public static void countDown1(int num) {.docx
public class ExampleCode2 {   public static void countDown1(int num) {.docxpublic class ExampleCode2 {   public static void countDown1(int num) {.docx
public class ExampleCode2 { public static void countDown1(int num) {.docx
 
Provide the Total Table Encoded file size for the image pictured that (1).docx
Provide the Total Table Encoded file size for the image pictured that (1).docxProvide the Total Table Encoded file size for the image pictured that (1).docx
Provide the Total Table Encoded file size for the image pictured that (1).docx
 
Provide an appropriate response- A university must choose a team of 6.docx
Provide an appropriate response- A university must choose a team of 6.docxProvide an appropriate response- A university must choose a team of 6.docx
Provide an appropriate response- A university must choose a team of 6.docx
 
Prove x is even (x+1)2 is odd (hint- use a direct proof).docx
Prove x is even (x+1)2 is odd (hint- use a direct proof).docxProve x is even (x+1)2 is odd (hint- use a direct proof).docx
Prove x is even (x+1)2 is odd (hint- use a direct proof).docx
 
Protein utilization by bacteria leads to generation of end products th.docx
Protein utilization by bacteria leads to generation of end products th.docxProtein utilization by bacteria leads to generation of end products th.docx
Protein utilization by bacteria leads to generation of end products th.docx
 
Project Scope Statement for the MXE Project Introduction - The purpo.docx
Project Scope Statement for the MXE Project   Introduction - The purpo.docxProject Scope Statement for the MXE Project   Introduction - The purpo.docx
Project Scope Statement for the MXE Project Introduction - The purpo.docx
 
Project Closing Document The purpose of this document is to capture.docx
Project Closing Document   The purpose of this document is to capture.docxProject Closing Document   The purpose of this document is to capture.docx
Project Closing Document The purpose of this document is to capture.docx
 
Problem II - Control of gastric acidity- 1- What is the trigger to tar.docx
Problem II - Control of gastric acidity- 1- What is the trigger to tar.docxProblem II - Control of gastric acidity- 1- What is the trigger to tar.docx
Problem II - Control of gastric acidity- 1- What is the trigger to tar.docx
 
Problem B (5 points)- The health board of a major city wants to know i.docx
Problem B (5 points)- The health board of a major city wants to know i.docxProblem B (5 points)- The health board of a major city wants to know i.docx
Problem B (5 points)- The health board of a major city wants to know i.docx
 
Problem B part a Suppose A-B are events with indicators IA-IB- What va.docx
Problem B part a Suppose A-B are events with indicators IA-IB- What va.docxProblem B part a Suppose A-B are events with indicators IA-IB- What va.docx
Problem B part a Suppose A-B are events with indicators IA-IB- What va.docx
 
Problem 8 and 9 Entropy is closely related to something known as Kolmo.docx
Problem 8 and 9 Entropy is closely related to something known as Kolmo.docxProblem 8 and 9 Entropy is closely related to something known as Kolmo.docx
Problem 8 and 9 Entropy is closely related to something known as Kolmo.docx
 
Problem 4-45 (LO- 4) Nell and Kirby are in the process of negotiating.docx
Problem 4-45 (LO- 4) Nell and Kirby are in the process of negotiating.docxProblem 4-45 (LO- 4) Nell and Kirby are in the process of negotiating.docx
Problem 4-45 (LO- 4) Nell and Kirby are in the process of negotiating.docx
 
Problem 3- Reynolds number (Problem 7 of the textbook) (4 points) A sa.docx
Problem 3- Reynolds number (Problem 7 of the textbook) (4 points) A sa.docxProblem 3- Reynolds number (Problem 7 of the textbook) (4 points) A sa.docx
Problem 3- Reynolds number (Problem 7 of the textbook) (4 points) A sa.docx
 
Problem 2 (20 points- graded on accuracy) Consider a circle of radius.docx
Problem 2 (20 points- graded on accuracy) Consider a circle of radius.docxProblem 2 (20 points- graded on accuracy) Consider a circle of radius.docx
Problem 2 (20 points- graded on accuracy) Consider a circle of radius.docx
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

Mbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptxMbaye_Astou.Education Civica_Human Rights.pptx
Mbaye_Astou.Education Civica_Human Rights.pptx
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
The Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdfThe Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdf
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdfPost Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 

Project 3- Frozen Yogurt with Mix-ins Assignment For this project- you.docx

  • 1. Project 3: Frozen Yogurt with Mix-ins Assignment For this project, you get to build off of the FrozenYogurt class from Project 2 and exercise using loops in Java! A very common application of loops is input validation. You will get to do that in this project. Additionally, you get to use either a StringBuilder or StringBuffer object to store multiple toppings in a FrozenYogurt object. FrozenYogurt class For the FrozenYogurt class make the following changes to that class: (Driver class will be separate) 1.Change the instance variable for the topping to be either a StringBuilder or StringBuffer object to appropriately support a comma-separated list of toppings (instead of just a single topping) 2.Change the setPrice method so that it returns a String. If the new price is negative, do not update the price and return a String with the following value: ALERT: Unable to set <name>'s price to <price> (negative values are not allowed) Where <name> is the name of the frozen yogurt and <price> is the parameter's value. If the price is 100.0 or greater, do not update the price and return a String with the following value: ALERT: Unable to set <name>'s price to <price> (value is too high (>=100.00)) Otherwise, return an empty string. 3.Change setYogurtFlavor method so that it returns a String. If the new flavor is not "chocolate" nor "vanilla", do not update the base flavor and return a String with the following value: ALERT: <new yogurt flavor> is not one of the valid yogurt flavors (chocolate or vanilla)! Where <new yogurt flavor> is the value of the parameter. If the new flavor is valid, then return an empty string. 4.Add an addTopping method that take a String as a parameter. If the instance variable already has a topping, then separate the previous value and the new value with ", ". Otherwise, just use the new topping as the value (without a ","). For each additional topping added, add $0.49 to the price. import java.util.Scanner; public class FrozenYogurt{ //private instance variables private String name; private double price;
  • 2. private String flavor; private String topping; //constructor with no parameters public FrozenYogurt(){ this.name = ""; this.price = 0.0; this.flavor = ""; this.topping = ""; } // constructor with parameters public FrozenYogurt(String name, double price, String flavor, String topping){ this.name = name; this.price = price; this.flavor = flavor; this.topping = topping; } // mutator methods public void setName(String name){ this.name = name; } public void setPrice(double price){ this.price = price; }
  • 3. public void setYogurtFlavor(String flavor){ this.flavor = flavor; } public void setTopping(String topping){ this.topping = topping; } //Accessor methods public String getName(){ return name; } public double getPrice(){ return price; } public String getYogurtFlavor(){ return flavor; } public String getTopping(){ return topping; } //toString method public String toString(){ return "Frozen Yogurt: " + name + "nPrice: $" + price + "nYogurt: " + flavor + "nToppping: " + topping + "n"; }
  • 4. //User inputs public String valueEntered(String s){ return "You entered: " + s + "n"; } } //driver class import java.util.Scanner; public class FrozenYogurtDriver { public static void main(String[] args) { //Scanner class Scanner sc = new Scanner(System.in); //object creation from FrozenYogurt FrozenYogurt froyo1 = new FrozenYogurt(); FrozenYogurt froyo2 = new FrozenYogurt(); System.out.println("Welcome to the Frozen Yogurt Selector"); //User inputs for object System.out.print("Please enter the name of the first frozen yogurt: "); froyo1.setName(sc.nextLine()); System.out.println(froyo1.valueEntered(froyo1.getName())); System.out.print("Please enter the name of the second frozen yogurt: "); froyo2.setName(sc.nextLine()); System.out.println(froyo2.valueEntered(froyo2.getName()));
  • 5. //User inputs for prices System.out.print("Please enter the price for the "+ froyo1.getName() + ": "); froyo1.setPrice(Double.parseDouble(sc.nextLine())); System.out.println(froyo1.valueEntered(String.valueOf(froyo1.getPrice()))); System.out.print("Please enter the price for the "+ froyo2.getName() + ": "); froyo2.setPrice(Double.parseDouble(sc.nextLine())); System.out.println(froyo2.valueEntered(String.valueOf(froyo2.getPrice()))); //User inputs for flavors System.out.print("Please enter the base yogurt flavor for " + froyo1.getName() +": "); froyo1.setYogurtFlavor(sc.nextLine()); System.out.println(froyo1.valueEntered(froyo1.getYogurtFlavor())); System.out.print("Please enter the base yogurt flavor for " + froyo2.getName() +": "); froyo2.setYogurtFlavor(sc.nextLine()); System.out.println(froyo2.valueEntered(froyo2.getYogurtFlavor())); //User inputs for toppings System.out.print("Please enter the topping to add to " + froyo1.getName() +": "); froyo1.setTopping(sc.nextLine()); System.out.println(froyo1.valueEntered(froyo1.getTopping())); System.out.print("Please enter topping to add to " + froyo2.getName() +": "); froyo2.setTopping(sc.nextLine()); System.out.println(froyo2.valueEntered(froyo2.getTopping())); //display toSting System.out.println(froyo1);