Computer Science, asked by ranjansanjayk, 13 days ago

Write a program to assign name of the item, quantity, unit price and
display name of the item and its total price in java 7th std

pls answer

Answers

Answered by diyarohil
0

Answer:

this is the code It might work for you

Explanation:

import java.util.Scanner;

public class Assignment2 {

public static void main(String[] args)

{

System.out.println("Please enter CSU I.D.");

Scanner input = new Scanner(System.in);

int csuid = input.nextInt();

int minvalue1 = 40000;

int maxvalue1 = 59999;

int minvalue2 = 60000;

int maxvalue2 = 79999;

int minvalue3 = 80000;

int maxvalue3 = 89999;

int i;

double bookbag = 40.00;

double textbook = 50.00;

double notebook = 3.00;

double pen = 1.00;

double pencil = 1.00;

double sweatpants = 35.00;

double shirt = 25.00;

double sweater = 30.00;

double candy = 2.00;

double planner = 15.00;

double sum = 0;

System.out.println("Please enter how many items you are going to purchase.");

int items = input.nextInt();

Scanner read = new Scanner(System.in);

if (items <= 10)

{

String itemArray[];

itemArray = new String[items];

if (csuid >= minvalue1 && csuid <= maxvalue1)

{

for(i = 0; i < items; i++ )

{

System.out.println("What would you like to purchase?");

String c = read.next();

itemArray[i] = c;

}

for(int counter = 0;counter < itemArray.length; counter++)

{

System.out.println(itemArray[counter] + " ");

}

System.out.println("Total Value " + sum);

}

else if (csuid >= minvalue2 && csuid <= maxvalue2)

{

for(i = 0; i < items; i++ )

{

System.out.println("What would you like to purchase?");

String c = read.next();

itemArray[i] = c;

for(int counter = 0;counter < itemArray.length; counter++)

{

System.out.println(itemArray[counter] + " ");

//sum += itemArray[counter];

}

System.out.println("Total Value " + sum);

}

System.out.println("Total Value " + sum);

}

else if (csuid >= minvalue3 && csuid <= maxvalue3)

{

for(i = 0; i < items; i++ )

{

System.out.println("What would you like to purchase?");

String c = read.next();

itemArray[i] = c;

for(int counter = 0;counter < itemArray.length; counter++)

{

System.out.println(itemArray[counter] + " ");

//sum += itemArray[counter];

}

System.out.println("Total Value " + sum);

}

System.out.println("Total Value " + sum);

}

else

{

System.out.println("Invalid CSU ID");

}

}

else

{

System.out.println("Cannot purchase " + items + " items");

}

read.close();

input.close();

}

Similar questions