Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Java Programming Help! Here\'s the scenario: Each year, PNC Advisors of Pit

ID: 3769742 • Letter: N

Question

Need Java Programming Help! Here's the scenario:

Each year, PNC Advisors of Pittsburgh publishes a "12 Days of Christmas" Price List. The price list is as follows:

I need to write a program that requests an integer from 1 through 12 and then lists the gifts for that day along with that day's cost. On the nth day, the n gifts are 1 partridge in a pear tree, 2 turtledoves, ...., n of the nth item. The program also should give the total cost of all twelve days.

EXAMPLE INPUT/OUTPUT: If the user inputs '3', the output dialogue box would say:

"The gifts for day 3 are: 1 Partridge in a Pear Tree, 2 Turtle Doves, 3 French Hens. Total cost: $92.50"

Note: The total cost for all 12 days would be $71,613.50

ITEM PRICE Partridge in a Pear Tree $27.50 Turtle Dove $25.00 French Hen $5.00 Calling Bird $70.00 Gold Ring $60.00 Geese-a-Laying $25.00 Swan-a-Swimming $1,000.00 Maid-a-Milking $4.25 Lady Dancing $289.50 Lord-a-Leaping $292.50 Piper Piping $95.75 Drummer Drumming $95.00

Explanation / Answer

This below Java Code is implemented as per given in problem statement and tested with result..
I have stored items and costs in two arrays..first I calculated cost of 12 items and displayed..
and then user will entered the item number and then calculated the total cost of user entered numbered and then displayed
the list of items also..See the below code implemented..with well written comments.

Source Code:

import java.util.Scanner;

// Declared a Price List Class
public class Pricelist
{
   public static void main(String args[])
   {
       // Created two Arrays for storing the Items and price of each items of 12 days.
       String item[] = {"Partridge in a Pear Tree", "Turtle Dove", "French Hen", "Calling Bird", "Gold Ring", "Geese-a-Laying",
       "Swan-a-Swimming","Maid-a-Milking","Lady Dancing","Lord-a-Leaping","Piper Piping","Drummer Drumming"};
       double price[] = {27.50,25.00,5.00,70.00,60.00,25.00,1000.00,4.25,289.50,292.50,95.75,95.00};
    
       // Defining total cost of 12 days
       double total = 0.0, temp = 0.0;
       int j =1;     
       for(int i = 0; i<12;i++)
       {
           temp = temp + price[i] * j;
           total = total + temp;
           j++;
       }
       // Displaying the total cost od 12 days
       System.out.println("Total Cost of 12 Items are: $"+total);
       // Read the user input and print the corresponding series of gifts
       System.out.println();
       Scanner sc=new Scanner(System.in);
       System.out.println("Enter your number between 1 to 12 inclusive of 1 and 12");
       int number=sc.nextInt();
    
       // Calculating the number of items cost entered by user
       double temp1 = 0.0, temp2 = 0.0;
       int k =1;
       for(int i = 0; i<number; i++)
       {
           temp2 = price[i] * k;
           temp1 = temp1 + temp2;
           k++;
       }
    
       // Displaying the corresponding Items and total cost of those user items count
       for(int i=0;i<number;i++)
           System.out.println(item[i]);
       System.out.println("Total Cost of "+number+" is :$"+temp1);    
    
   }
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote