SlideShare ist ein Scribd-Unternehmen logo
1 von 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!");
}
}

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Kürzlich hochgeladen (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

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);