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

java on eclipse metrostate.learn minnstate.edu Program 1- Due Sept 11 - ICS 141-

ID: 3744884 • Letter: J

Question

java on eclipse

metrostate.learn minnstate.edu Program 1- Due Sept 11 - ICS 141-01 y Drive - Google Drive Eclipse Downloads I The Eclipse You have been asked to write a program to help retail store clerks calculate the amount of money a customer owes. In this simplistic world, every customer buys exactly three kinds of items. However, the quantity of each item they purchase may vary Inputs (entered by user of the program) Description/name of one item Price for one item Quantity purchased Description/name of second item Price for second item Quantity purchased Description/name of third item Price for third item Quantity purchased Tax rate (between O and 1.0) Processing and Output Calculate and display the line item total for each item Calculate and display the total cost of all the items Calculate and display the tax on all the items Calculate and display the grand total (total cost of items+tax) Display your name

Explanation / Answer

package org.students;

import java.util.Scanner;

public class Store1 {

public static void main(String[] args) {

//Declaring variables
String names[] = new String[3];
double price[] = new double[3];
int qty[] = new int[3];
double tax, allItemsTot = 0, grandTot = 0;

/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);

for (int i = 0; i < 3; i++) {
System.out.println("Item#" + (i + 1) + ":");
//Getting the input entered by the user
System.out.print("Enter Name:");
names[i] = sc.nextLine();
System.out.print("Enter Price:$");
price[i] = sc.nextDouble();
System.out.print("Enter quantity:");
qty[i] = sc.nextInt();
sc.nextLine();
}

while (true) {
System.out.println("Enter tax rate between 0.0 and 1.0 :");
tax = sc.nextDouble();
if (tax <= 0 || tax >= 1.0)
System.out.println("** Invalid.Must be between 0 and 1.0 **");
else
break;
}


for (int i = 0; i < 3; i++) {
System.out.println("Total cost of Item#" + (i + 1) + ":$" + (qty[i] * price[i]));
allItemsTot += qty[i] * price[i];
}

grandTot = (allItemsTot) + ((allItemsTot) * tax);
System.out.println("Total cost of all items :$" + allItemsTot);
System.out.println("Tax on all the items :$" + (allItemsTot) * tax);
System.out.println("Grand total :$" + grandTot);

}

}

________________

Output:

Item#1:
Enter Name:Mobile
Enter Price:$250
Enter quantity:20
Item#2:
Enter Name:Pern Drive
Enter Price:$40
Enter quantity:50
Item#3:
Enter Name:Hard Drisk
Enter Price:$130
Enter quantity:20
Enter tax rate between 0.0 and 1.0 :
0.20
Total cost of Item#1:$5000.0
Total cost of Item#2:$2000.0
Total cost of Item#3:$2600.0
Total cost of all items :$9600.0
Tax on all the items :$1920.0
Grand total :$11520.0

_________Thank You