×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

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

July 02, 2024
Prof. Alexander Choice
Prof. Alexander
🇬🇧 United Kingdom
Java
Prof. Alexander Mitchell, based in the UK, is an esteemed Java programmer with extensive academic credentials. He has successfully delivered over 900 assignments on object inheritance and polymorphic class topics. Prof. Mitchell's expertise lies in designing scalable Java applications, optimizing code efficiency, and mentoring students in software development practices.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Ensure you understand the dataset thoroughly before starting your machine learning assignment. Visualize the data, check for missing values, and identify patterns or anomalies to guide your model-building process effectively.
News
In 2024, universities have introduced new programming courses focusing on cybersecurity, machine learning, and artificial intelligence to better prepare students for modern IT careers.

Instructions

Objective

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

QUESTION 7

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

QUESTION 8

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

What is the name of the variable in the line above?

QUESTION 10

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

HOTEL

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

QUESTION

import javax.swing.*; public class Question6 { public static void main(String[] args) { // Define costs here int VAINILLA_PRICE = 7; int CARAMEL_PRICE = 12; int SPECIAL_PRICE = 14; double DISCOUNT = 0.1; // discount to apply for total if liters higher than 5 while(true) { try { // 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); break; } else JOptionPane.showMessageDialog(null, "Please enter positive values."); } catch(Exception ex) { JOptionPane.showMessageDialog(null, "Please enter valid numeric values."); } } } }

Related Samples

At ProgrammingHomeworkHelp.com, students can access an extensive collection of related samples for Java assignments. Our platform is dedicated to providing top-notch assignment support, ensuring students grasp complex Java concepts and enhance their coding skills. With expertly crafted Java samples, students can explore various topics and methodologies, gaining valuable insights to excel in their academic pursuits. Whether you're tackling object-oriented programming, data structures, or algorithms, our Java samples serve as a practical guide to help you succeed. Trust ProgrammingHomeworkHelp.com for all your Java assignment needs.