Question

In: Computer Science

ITSC 1212 – Programming Checkpoint 3 – Candle Shop The main idea behind this activity is...

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:

  1. Prompt the user to enter the number of candles of each type the customer wants to buy. Since you can’t buy a fraction of a candle, the input for each type of candle must be an integer. (You may assume that only integer values between 0 and 10 will be entered when this program is tested.)
  2. Calculate the total price of all the candles bought using the information in the table above. For example, two Type 1 candles and one Type 2 candle would have a total price of $8.75.
  3. Calculate the total burn time of all the candles if they were burned consecutively (i.e., one after the other). For example, one Type 1 and one Type 3 candles would burn for 17 hours.
  4. Calculate the cost-per-minute for that purchase.
  5. Output some kind of meaningful display that includes the number of candles of each type bought, the total price, the total burn time, and the cost-per-minute. You can be as creative as you want with this!

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:

  • the class should be name CastleShop.
  • the program will need to import the Scanner class from the Java util package.
  • the class should have a main method that will include the logic for the algorithm you developed in Part A. You may choose to add additional methods that are called in the main method.

Solutions

Expert Solution

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!


Related Solutions

Thoughts on this: "Rule by the people" is the main idea behind democracy. Ideally, in a...
Thoughts on this: "Rule by the people" is the main idea behind democracy. Ideally, in a democratic society, we either elect our representatives, who, in theory, govern as the people see fit, or directly vote on issues. The procedural side of democracy guides the electoral processes of our society such as deciding who should vote, the weight that vote should carry, and how decisions are made using those votes. The substantive side of "rule by the people" delves into the...
Discuss the idea behind the phrase, “Leadership is an activity, not a position.” Please conduct research...
Discuss the idea behind the phrase, “Leadership is an activity, not a position.” Please conduct research to support your findings, citing at least one scholarly resource (in addition to the required reading) in APA format.
At the end of Chapter 11, it mentioned "creative destruction." What is the main idea behind...
At the end of Chapter 11, it mentioned "creative destruction." What is the main idea behind that term? 1-The idea that a competitive marketplace will also be a creative one and that we should see new technologies and inventions as entreprenueurs try to "out do" each other. When downloading music became popular this pretty much eliminated the need for physical audio CDs. This was an example of creative destruction. 2-It is highly doubtful that a centrally planned communist economy (i.e....
Please explain what is the main idea behind differential analysis. What are relevant or differential costs?...
Please explain what is the main idea behind differential analysis. What are relevant or differential costs? What are the two necessary characteristics of differential costs? Can fixed costs be differential or relevant in your decision?
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array...
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array to test, thanks. get_location_of_min This function takes a matrix as a 2-D array of integers with NUM_COLS width, the number of rows in the matrix and two integer pointers. The function finds the location of the minimum value in the matrix and stores the row and column of that value to the memory location pointed to by the pointer arguments. If the minimum value...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT