+1 (315) 557-6473 

Create a Program to Implement Ice Cream Buying System in Java Assignment Solution.


Write a java assignment program to implement ice cream buying system.

Requirements and Specifications

Question 6
Using GUI:
import javax.swing.*;
public class NameOfYourClass {
public static void main (String[] args) {
// to read use: JOptionPane.showInputDialog("message")
// to write use:
// OptionPane.showMessageDialog(null,str,"message",JOptionPane.INFORMATION_MESSAGE);
An online system allows you to buy icecream. The prices are:
$7 for 1 litre of vanilla or chocolate.
$12 for 1 litre of caramel .
$14 for 1 litre of the special of the day .
If the the customer orders more than 5 litres of icecream, the client will receive a 10% discount.
Write a Java program that asks for the quantity (in litres) of icecream of each type, and displays the total amount due. If the user enters a negative number, the program should show a message and ask for the input again. You do not need to implement multiple classes for this question. You can include your code within either of the main method constructs as shown above.
For example, if the input is:
3 litres of vanilla icecream
4 litres of caramel icecream
The total amount will be 3*7+4*12 = 69. Since the total is more than 5 litres, the amount will have a 10% discount. So, the final amount is 69*0.9 = 62.1
  1. Write a program in Java that asks a value n and x, and calculates and display the result of the following expression. Your program should check if n is greater or equal to 1 and a odd number. If it is not, ask the user to input again. You don't need to check the value of x. Do not use any method from the Math class in your solution.
3x - 5x + 7x… nx
For example,
if n=7 and x=2, the result will be 32 - 52 + 72 = 33
if n=9 and x=2, the result will be 32 - 52 + 72 -92 = -48
  1. Consider a class called Hotel. This class will have the instance variables:
name (String - name of the hotel
priceLow (double - price of the room with the cheapest rate)
priceHigh (double - price of the room with the highest rate).
The methods will be
setName (the parameter will be a String that will be stored in the variable name)
getName (it will return the name of the hotel)
setPriceLow (the parameters will be a double that will be stored in priceLow)
setPriceHigh (the parameters will be a double that will be stored in priceHigh)
getPriceLow (it will return the priceLow)
getPriceHigh (it will return the priceHigh)
All variables are private and all methods are public.
Write the implementation of this class in Java.
Question 9
Suppose now another class called BeachHotelCollection. Suppose the class BeachHotelCollection has the following declaration
Hotel p = new Hotel(“Hyatt”,300, 800);
Which is the name of the variable in the line above?
  1. Continuing on from the previous question: Is it correct the statement p.priceLow =300;?
If it is not correct, write the correct statement to store 300 in priceLow.
Justify your answer.
Source Code
public class Hotel {
private String name;
private double priceLow;
private double priceHigh;
// constructor
public Hotel(String name, double priceLow, double priceHigh)
this.name = name;
this.priceLow = priceLow;
this.priceHigh = priceHigh;
// methods
public void setName(String newName) {name = newName;}
public String getName() {return name;}
public void setPriceLow(double newlow) {priceLow = newlow;}
public double getPriceLow() {return priceLow;}
public void setPriceHigh(double newhigh) {priceHigh = newhigh;}
public double getPriceHigh() {return priceHigh;}
import javax.swing.*;
public class Question6 {
public static void main(String[] args)
// Define costs here
double DISCOUNT = 0.1; // discount to apply for total if liters higher than 5
// ask for liters
int n_vainilla = Integer.valueOf((String)JOptionPane.showInputDialog(null, "Enter liters of Vainilla Icecream"));
int n_caramel = Integer.valueOf((String)JOptionPane.showInputDialog(null, "Enter liters of Caramel Icecream"));
int n_special = Integer.valueOf((String)JOptionPane.showInputDialog(null, "Enter liters of Special Of The Day Icecream"));
if(n_vainilla > 0 && n_caramel > 0 && n_special > 0)
// calculate sub-total
double subtotal = n_vainilla*VAINILLA_PRICE + n_caramel*CARAMEL_PRICE + n_special*SPECIAL_PRICE;
// check discount
int total_liters = n_vainilla + n_caramel + n_special;
double total = subtotal;
if(total_liters > 5)
total = total*(1.0-DISCOUNT);
// show result
String message = String.format("You ordered:\n\nVainilla Icecream: %d liters\nCaramel Icecream: %d liters\nSpecial of the day: %d liters\n\nSubtotal: $%.2f\nDiscount: $%.2f (%.0f)\nTotal: $%.2f", n_vainilla, n_caramel, n_special, subtotal, DISCOUNT*subtotal, DISCOUNT*100.0, total);
JOptionPane.showMessageDialog(null, message);
JOptionPane.showMessageDialog(null, "Please enter positive values.");
catch(Exception ex)
JOptionPane.showMessageDialog(null, "Please enter valid numeric values.");