In: Computer Science
ITSC 1212 – Programming Checkpoint 3 – Candle Shop
The main idea behind this activity is to create a program that accepts multiple inputs from a user and use that information to control the operation of the method.
Preliminaries
The owner of a candle shop has asked for your help. The shop sells three types of candles as shown below:
Type |
Price |
Burn Time (hours) |
1 |
$2.50 |
5 |
2 |
$3.75 |
7 |
3 |
$5.99 |
12 |
The owner wants you to write a program to perform certain calculations when customers buy different numbers of the candles.
Part A – Develop an algorithm (5 points)
Develop an algorithm to satisfy the following requirements:
Write the pseudocode for the algorithm and store it in a file (file format can be text, pdf or doc) with the name CandleShopSteps.
Part B – Write the code (20 points)
Once you've written your algorithm it is time to turn it into a Java program. that can be executed (run). Here are some things to keep in mind:
You can have reference to the comments in the code for algorithm. Algorithm is same as the comments I have given for simplicity.
Have a look at the below code and the sample output.
import java.util.Scanner;
class CastleShop{
// main method
public static void main(String[] args) {
// create scanner object
Scanner sc = new Scanner(System.in);
// create variables to store type of candles
int type1,type2,type3;
System.out.println("Enter number of candles you want to buy of Type 1");
// take user input of candle type 1
type1 = sc.nextInt();
System.out.println("Enter number of candles you want to buy of Type 2");
// take user input of candle type 2
type2 = sc.nextInt();
System.out.println("Enter number of candles you want to buy of Type 3");
// take user input of candle type 3
type3 = sc.nextInt();
// create varible to store total price
double totalPrice = 0.0;
// multiply number of candles by their price and sum in the total price
totalPrice+=(type1*2.5);
totalPrice+=(type2*3.75);
totalPrice+=(type3*5.99);
// create variable for total burn time
int totalBurnTime = 0;
// multiply number of candles by their burn time and sum in the total price
totalBurnTime+=(type1*5);
totalBurnTime+=(type2*7);
totalBurnTime+=(type3*12);
// calculate cost per minute, also conver the time in minutes by multiplying it by 60
double costPerMinute = (totalPrice/(totalBurnTime*60));
// Display the results...
System.out.println("Total candles of Type 1: " + type1);
System.out.println("Total candles of Type 2: " + type2);
System.out.println("Total candles of Type 3: " + type3);
System.out.println("Total price of candles: " + totalPrice);
System.out.println("Total burn time of candles: " + totalBurnTime);
System.out.println("Cost per minute: " + costPerMinute);
}
}
Happy Learning!