IN JAVA
Laboratory 3: Ice Cream!
Download Lab03.zip from ilearn and extract it into your working lab 3 directory
In this lab, you will be writing a complete class from scratch, the IceCreamCone class. You will also write a driver to interact with a user and to test all of the IceCreamCone methods.
Lab:
• Cone
• Ice Cream
o Flavor
o Topping
• Ice Cream Cone
• Driver
Part I: Cone
An ice cream cone has two main components, the flavor of ice cream and the type of cone. Write a Cone class that takes an integer in its constructor. Let a 1 represent a sugar cone, let a 2 represent a waffle cone, and let a 3 represent a cup. It will help to use a private variable in order to keep track of the cone type amongst your methods. Make sure to set an invalid entry to a default cone (the choice of default is up to you). Write a method to return the price of the cone. The sugar cone is $0.59, the waffle cone is $0.79, and the cup is free. Write a toString() method to return a String indicating the type of cone that was selected.
Note: If you need a carriage return in a String, use "\r\n"
Part II: Ice Cream
Download the following files:
• Topping.java
o public double price() //toppings are $0.15 ("no topping" is
free)
• Toppings.java //this file has the following public
interface:
o public static Toppings getToppings() //singleton design
pattern
o public int numToppings() //the number of different toppings
o public String listToppings() //list (and number) available
toppingso public Topping getTopping(int index) //1-based
Flavor.java
Flavors.java //this file has the following public interface:
o public static Flavors getFlavors() //singleton design
pattern
o public int numFlavors() //the number of different flavors
o public String listFlavors() //list (and number) available
flavorso public Flavor getFlavor(int index) //1-based
Ice cream has a number of scoops, a flavor, and a topping. Write an IceCream constructor that accepts the number of scoops (up to 3), a Flavor object, and a Topping object. It will help to use private variables in order to keep track of the number of scoops, your flavor, and your topping amongst your methods. Set default values (up to you) if the input is invalid (make sure to protect against null). Write a method to return the price
(each scoop over 1 adds $0.75 to the cost of the ice cream) and a method to return a String listing the ice cream parameters selected.
Part III: Ice Cream Cone
Download the following file:
• Currency.class //this file has the following public
interface:
o public static String formatCurrency(double val) //formats the
double as a String representing US
currency
It will help to use private variables in order to keep track of your cone and ice cream amongst your methods. Use Currency.class to format the total price of the Ice Cream Cone.
Note: Without using the Currency class, it is possible to get final prices that are not quite correct, such as 3.5300000000000002.
The IceCreamCone is composed of the Cone and the IceCream. Write a constructor that accepts an IceCream
and a Cone (protect against null), a method to return the price (the base price is $1.99 plus any costs
associated with the components), and a method to return a String display of the ice cream cone ordered by the
user.
Part IV: Ice Cream Driver
Download the following file:
• Keyboard.class //this file has the following public
interface:
o public static Keyboard getKeyboard() //singleton design patterno
public int readInt(String prompt)
o public double readDouble(String prompt)
o public String readString(String prompt)
defensive programming
In addition to main, include the following methods in your driver:
This is
Write a driver to obtain the ice cream cone order from the user. Allow multiple ice cream cones to be ordered,
and keep a
running total
of the price of the ice cream cones. Of course, wait (loop) for the user to input valid
entries. Thus, you are checking for valid entries in the driver and in the constructor of your objects.
, although it results in some code duplication.
public static Flavor getFlavorChoice() //look at the methods available in the Flavors class
public static Topping getToppingChoice() //look at the methods available in the Toppings class
public static int getScoopsChoice()
public static Cone getConeChoice()
All of these methods take input from the user (using
Keyboard.class) Example output included as a jpg in Lab03
files.
To compile: javac *.java
To run: java IceCreamDriver
You can also run your driver with my input file via: java IceCreamDriver < ice_cream.txt (or by running make.bat)
CURRENCY.JAVA
import java.text.DecimalFormat;
public class Currency
{
private final static DecimalFormat fmt = new
DecimalFormat("#,##0.00");
public static String formatCurrency(double val)
{
String temp = "$" + fmt.format(val);
return temp;
}
}
TOPPING.JAVA
public enum Topping
{
nuts(0.15), m_and_ms(0.15), hot_fudge(0.15), oreo_cookies(0.15),
no_topping(0.00);
private double toppingPrice;
private Topping(double price)
{
toppingPrice = price;
}
public double price()
{
return toppingPrice;
}
}
TOPPINGS.JAVA
public class Toppings
{
private static Toppings toppings = new Toppings();
private Topping[] all_toppings;
private Toppings()
{
all_toppings = Topping.values();
}
public static Toppings getToppings()
{
return toppings;
}
public int numToppings()
{
return all_toppings.length;
}
public String listToppings()
{
int index = 1;
//loop through the enumeration, listing the flavors
String topping_str = "";
for (Topping top : all_toppings)
{
topping_str += index + ". " + top.toString() + "\r\n";
index++;
}
return topping_str;
}
public Topping getTopping(int index) //1-based
{
int num_toppings = numToppings();
if (index < 1 || index > num_toppings)
{
index = 1;
}
return all_toppings[index - 1];
}
}
FLAVOR.JAVA
public enum Flavor
{
chocolate, vanilla, coffee, mint_chocolate_chip, almond_fudge,
pistachio_almond,
pralines_and_cream, cherries_jubilee, oreo_cookies_and_cream,
peanut_butter_and_chocolate,
chocolate_chip, very_berry_strawberry, rocky_road, butter_pecan,
chocolate_fudge, french_vanilla,
nutty_coconut, truffle_in_paradise;
}
FLAVORS.JAVA
public class Flavors
{
private static Flavors flavors = new Flavors();
private Flavor[] all_flavors;
private Flavors()
{
all_flavors = Flavor.values();
}
public static Flavors getFlavors()
{
return flavors;
}
public int numFlavors()
{
return all_flavors.length;
}
public String listFlavors()
{
int index = 1;
//loop through the enumeration, listing the flavors
String flavor_str = "";
for (Flavor flavor : all_flavors)
{
flavor_str += index + ". " + flavor.toString() + "\r\n";
index++;
}
return flavor_str;
}
public Flavor getFlavor(int index)
{
int num_flavors = numFlavors();
if (index < 1 || index > num_flavors)
{
index = 1;
}
return all_flavors[index - 1];
}
}
KEYBOARD.JAVA
public class Keyboard
{
private static Keyboard kb = new Keyboard();
/** The SDK provided Scanner object, used to obtain keyboard
input */
private java.util.Scanner scan;
private Keyboard()
{
scan = new java.util.Scanner(System.in);
}
public static Keyboard getKeyboard()
{
return kb;
}
/**
* Reads an integer from the keyboard and returns it.
* Uses the provided prompt to request an integer from the
user.
*/
public int readInt(String prompt)
{
System.out.print(prompt);
int num = 0;
try
{
num = scan.nextInt();
readString(""); //clear the buffer
}
catch (java.util.InputMismatchException ime) //wrong type
inputted
{
readString(""); //clear the buffer
num = 0;
}
catch (java.util.NoSuchElementException nsee) //break out of
program generates an exception
{
readString(""); //clear the buffer
num = 0;
}
return num;
}
/**
* Reads a double from the keyboard and returns it.
* Uses the provided prompt to request a double from the user.
*/
public double readDouble(String prompt)
{
System.out.print(prompt);
double num = 0.0;
try
{
num = scan.nextDouble();
readString(""); //clear the buffer
}
catch (java.util.InputMismatchException ime)
{
readString(""); //clear the buffer
num = 0;
}
catch (java.util.NoSuchElementException nsee)
{
readString(""); //clear the buffer
num = 0;
}
return num;
}
/**
* Reads a line of text from the keyboard and returns it as a
String.
* Uses the provided prompt to request a line of text from the
user.
*/
public String readString(String prompt)
{
System.out.print(prompt);
String str = "";
try
{
str = scan.nextLine();
}
catch (java.util.NoSuchElementException nsee)
{
readString(""); //clear the buffer
str = "";
}
return str;
}
}
In: Computer Science
The five basic components of promotion include advertising, sales promotions, social media, publicity, and personal selling. All five components of the retailer’s promotion mix need to be managed from a total systems perspective.
All non-essential retail businesses are closed due to the COVID-19 lockdown. At some point (hopefully in the near future) we will return to normal and these businesses will reopen.
While these businesses will be receiving financial support from the government, many are going to be in a tight situation, and fighting for every dollar when the doors finally open. So, they will need to rely on sales promotion, publicity, social media and personal selling to succeed. Those that don’t get out of the gate strong may not survive.
Choose one of the following retailers: Hair Cuttery; Hand and Stone Massage; Modell’s; Caesars casino; or Outback Steakhouse.
Describe the best way your retailer choice can use the
four promotional components (sales promotion, publicity, social
media and personal selling) to be successful when the lockdown is
over.
In: Operations Management
Who within an organization should initiate the first kick-off of an idea for expansion or improving of assets? And why? Discuss.
In: Operations Management
this question has been answered incorrectly several times can someone answer it correctly and show me some examples of a run
Design and implement a class named Person and its two subclasses named Student and Employee.
Make Faculty and Staff subclasses of Employee.
A person has a name,address, phone number, and email address.
A student has a class status (year 1,year 2,year 3,or year 4).
An employee has an office, salary, and date hired.
Use the Date class from JavaAPI 8 to create an object for date hired.
A faculty member has office hours and a rank.
A staff member has a title.
Override the toString method in each class to display the class name and the person’s name.Design and implement all 5classes.
Write a test program that creates a Person,Student,Employee,Faculty, and Staff, and iinvokes their toString()methods
In: Computer Science
In: Operations Management
In: Psychology
In: Accounting
Sarah is buying a home. Her loan will be $100,000. She will make annual payments for the next 30 years to retire this loan. The interest rate on the loan is 4 %.
A. How much will her annual payments be?
B. How much interest will she pay over the life of the loan?
C. How much of her first payment will be applied to principal?
D. How much will she still owe on the loan after 10 years?
In: Finance
Carlos and Shannon are sledding down a snow-covered slope that is angled at 12.0° below the horizontal. When sliding on snow, Carlos’s sled has a coefficient of friction μk = 0.100; Shannon has a “supersled” with μk = 0.0100. Carlos takes off down the slope starting from rest. When Carlos is 4.00 m from the starting point, Shannon starts down the slope from rest.
How far have they traveled when Shannon catches up to Carlos?
How fast is Shannon moving with respect to Carlos as she passes by?
In: Physics
Can anyone fix this code? The code isn't rounding the answer to the nearest whole number like 2.345 should be 2 and 2.546 should be 3 but the round() function isn't working as expected. The round() function is rounding 2.546 to 2 which is incorrect since 4 and below should be rounded to 2 and 5 and above should be rounded to 3.
Here is the code:
#importing xlwt library to write into xls
import xlwt
from xlwt import Workbook
#create a workbook
wb = Workbook()
#create a sheet
sheet = wb.add_sheet('Sheet')
#percentages list
percentages = [23.6, 38.2, 50, 61.8, 78.6, 113, 123.6, 138.2,
161.8]
#add first row
for i in range(len(percentages)):
sheet.write(0,i+1,str(percentages[i])+'%')
#user input
n = int(input('Enter number of elements: '))
#second row starts from index 1
row=1
print('Enter numbers: ')
for i in range(n):
#User input
val = float(input())
#Add entered value to first column of the row
sheet.write(row,0,str(val))
#calculate each percentage
for j in range(len(percentages)):
result =
(percentages[j]/100)*val
#write result to sheet by rounding
upto 3 decimal points
sheet.write(row,j+1,str(round(result,3)))
#increment the row by 1
row+=1
#save Workbook as xls`
wb.save('percentages.xls')
Thank you so much for anyone who helped!
In: Computer Science
International Accounting
What are the market transaction methods? Describe what is done in each of the market transaction methods.
what is the single rate / current rate translation methods? What is the temporal method? Describe what is done in each of the translations.
In: Accounting
In: Operations Management
Identify and explain two ways that human resources professionals
can support managers. Identify and explain two ways that
controllers can support managers. Why is it important for managers
to work collaboratively with controllers, human resource
professionals and other internal stakeholders and leaders within
the company?
In: Operations Management
Python Programming 4th edition: Write a program that asks the user for the number of hours (float) and the pay rate (float) for employee pay role sheet. The program should display the gross pay with overtime if any and without overtime. Hints: Given base_hr as 40 and ovt_multiplier as1.5, calculate the gross pay with and Without overtime. The output should look like as follows: Enter the number of hours worked: Enter the hourly pay rate: The gross pay is $XXX.XX
In: Computer Science
A director at an assisted living facility wants to offer a range of programs that support aging residents' cognitive functioning. What activities and interventions would you recommend, and why in 200 words.
In: Nursing