In: Computer Science
1) Write Java application that asks the user to enter the cost
of each apple and number of apples bought. Application obtains the
values from the user and prints the total cost of apples.
2) Write a java application that computes the cost of 135 apples,
where the cost of each apple is $0.30.
3)Write a java application that prepares the Stationery List.
Various entries in the table must be obtained from the user.
Display the Stationary list in the tabular format
Program 1:
import java.util.*;
class App1
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int numApples;
double cost,totalCost;
System.out.print("\n\nEnter the cost of each Apple : $");
cost=input.nextDouble();
System.out.print("\nEnter number of apples Bought : ");
numApples=input.nextInt();
totalCost=cost*numApples; //calculating total cost
System.out.println("\nTotal cost of Apples :
$"+totalCost);
System.out.println("\n");
}
}
Program 2:
class App2
{
public static void main(String args[])
{
int numApples=135;
double cost=0.30, totalCost;
totalCost=cost*numApples; //calculating total cost
System.out.println("\nTotal cost of Apples : $"+totalCost);
System.out.println("\n");
}
}
Program 3:
import java.util.*;
class App3
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int qty;
double rate,total,gtotal=0;
String itemName;
String list="";
while(true)
{
System.out.print("\nEnter Item Name : ");
itemName=input.next();
System.out.print("Enter Quantity : ");
qty=input.nextInt();
System.out.print("Enter rate : ");
rate=input.nextDouble();
total=qty*rate;
list=list+itemName+"\t\t"+qty+"\t\t"+rate+"\t"+total+"\n";
gtotal=gtotal+total;
System.out.print("Do you want to add next Item (yes/no): ");
String yesNo=input.next();
if(yesNo.equalsIgnoreCase("no"))
{
break;
}
}
System.out.println("\n\nItemName\tQuantity\tRate\ttotal\n\n");
System.out.println(list);
System.out.println("Total amount: "+gtotal);
System.out.println("\n");
}
}