JAVA ASSIGNMENT Overview For this assignment you will design

JAVA ASSIGNMENT

Overview

For this assignment, you will design a program that will use a loop to accept the names of ten items and the raw cost of each item. The names and the item raw costs will be stored in two parallel arrays. The program will then output the names or the items, item raw costs and item prices (calculated using the formula itemCost(x) * 1.3) in table form with the column title \"Item Name\" above the names, the title \"Item Cost\" above the raw costs and the title \"Item Price\" above the prices.

Instructions

You will require two parallel arrays for the input.

The output will be formatted as an evenly-spaced table with at least seven spaces between each column.

You will output the total cost of goods at the bottom of the table. (Hint: Use an accumulator.) Do not use a separate loop to complete this part of the task.

Your program will have at least six methods:

The main method that coordinates the program\'s function.

The user will control when the data entry begins (see the output example).

A method that greets the user and provides brief instructions.

A method that prompts for and accepts input from the user.

A method that outputs the table.

A method that thanks the user and says goodbye.

Your program will end when the table output is complete and the user has been thanked.

Solution

InventoryTable.java

import java.text.DecimalFormat;
import java.util.Scanner;

public class InventoryTable {
  
   //Scanner class object is used to read the inputs entered by the user
   static Scanner sc=new Scanner(System.in);
   public static void main(String[] args) {
   //Calling the method  
   greetMethod();
     
   //Calling the method
   char ch=beginOrEnd();
     
   /* If the user input is B then get the data entered by the user
   * If entered E program will exit
   */
   if(ch==\'B\'||ch==\'b\')
   {
       //Calling the method which will accept the inputs entered by the user
   getInputs();     
  
   //Calling the method which will display by message
   sayThanks();
   }
   else if(ch==\'E\' || ch==\'e\')
   {
   System.out.println(\":: Program Exit ::\");
   }      

   }

   //This method will ask the character entered by the user
   private static char beginOrEnd() {
      
       System.out.print(\"Enter B to Begin and E to End :\");
       char ch= sc.next(\".\").charAt(0);
       return ch;
   }

   //This method will display the method message
   private static void sayThanks() {
       System.out.println(\"Thank You. Good Bye!\");
      
   }

   //This method will get the inputs entered by user
   private static void getInputs() {
      
       //Creating two String arrays of size 10
       String items[]=new String[10];
       double cost[]=new double[10];
      
       //Getting the data entered by the user
       for(int i=0;i<10;i++)
       {
               System.out.print(\"\ Enter Product \"+(i+1)+\" name :\");
               items[i]=sc.next();
               System.out.print(\"Enter the item cost :$\");
               cost[i]=sc.nextDouble();
       }
      
       //Calling the method which will display the table
       displayTable(items,cost);
      
   }

  
   //This method will display the data in the table format
   private static void displayTable(String[] items, double[] cost) {
       double total_cost=0.0;
       System.out.printf(\"%20s%22s%25s\ \",\"Item Name\",\"Item Cost\",\"Item Price\");
      
       //Displaying the table
       for(int i=0;i<10;i++)
       {
           System.out.format(\"%20s%17s%.2f%19s%.2f\ \",items[i],\"$\",cost[i],\"$\",cost[i]*1.3);
           total_cost+=cost[i];
       }
       //Displaying the total cost
       System.out.printf(\"\ Total Cost of Goods is %.2f:\",total_cost);
   }

  
   //This method will greet the user
   private static void greetMethod() {
       System.out.println(\"Welcome to the inventory Tracker Program\");
       System.out.println(\"This Program will accept the names and costs for 10 stocked items.\");
       System.out.println(\"The Program will then output a tablw with the names ,costs,and prices of the items.\");
       System.out.println(\"Prices are calculated with a 30% markup on cost.\");
      
      
   }

}

_______________________________

Output:

Welcome to the inventory Tracker Program
This Program will accept the names and costs for 10 stocked items.
The Program will then output a tablw with the names ,costs,and prices of the items.
Prices are calculated with a 30% markup on cost.
Enter B to Begin and E to End :B

Enter Product 1 name :Television
Enter the item cost :$439.65

Enter Product 2 name :Radio
Enter the item cost :$40.00

Enter Product 3 name :Computer
Enter the item cost :$525.99

Enter Product 4 name :Headphones
Enter the item cost :$139.65

Enter Product 5 name :Printer
Enter the item cost :$89.94

Enter Product 6 name :Monitor
Enter the item cost :$189.94

Enter Product 7 name :Keyboard
Enter the item cost :$29.94

Enter Product 8 name :Mouse
Enter the item cost :$19.94

Enter Product 9 name :Router
Enter the item cost :$69.94

Enter Product 10 name :Speakers
Enter the item cost :$49.94
Item Name Item Cost Item Price
Television $439.65 $571.55
Radio $40.00 $52.00
Computer $525.99 $683.79
Headphones $139.65 $181.55
Printer $89.94 $116.92
Monitor $189.94 $246.92
Keyboard $29.94 $38.92
Mouse $19.94 $25.92
Router $69.94 $90.92
Speakers $49.94 $64.92

Total Cost of Goods is 1594.93:Thank You. Good Bye!

_____________Thank You

JAVA ASSIGNMENT Overview For this assignment, you will design a program that will use a loop to accept the names of ten items and the raw cost of each item. The
JAVA ASSIGNMENT Overview For this assignment, you will design a program that will use a loop to accept the names of ten items and the raw cost of each item. The
JAVA ASSIGNMENT Overview For this assignment, you will design a program that will use a loop to accept the names of ten items and the raw cost of each item. The

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site