Question

In: Computer Science

1) Write Java application that asks the user to enter the cost of each apple and...

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

Solutions

Expert Solution

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");
}
}


Related Solutions

Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
Write a program that asks the user to enter the total precipitation for each of the...
Write a program that asks the user to enter the total precipitation for each of the twelve months of the year into a list. The program should calculate and display the total precipitation for the year, the average monthly precipitation, and the months with the highest and lowest precipitation amounts. FYI: precipitation is measured in inches. Assume that precipitation amounts are floating-point numbers. You will need a list to store the precipitation amounts and another list to store the names...
Design, plan, test, and write a computer program in Java that asks the user to enter...
Design, plan, test, and write a computer program in Java that asks the user to enter 1 number and a String. You will display the first n characters of the string where n is the number entered. For example, if the user enters 3 and java then you will print jav. If they enter 5 and Halloween then you print Hallo. If the user enters a number less than 0 then set the number to 0. Assume the user will...
Write a java program which asks the user to enter name and age and calls the...
Write a java program which asks the user to enter name and age and calls the following methods: printName(): Takes name as parameter and prints it 20 times using a while loop. printAge(): Takes age as parameter and prints all the numbers from 1 up to age. Write a java program that will print first 10 multiples of 3 in a single line.
Write a program that asks the user to enter an item’s wholesale cost and the markup...
Write a program that asks the user to enter an item’s wholesale cost and the markup percentage. It should then display the item’s retail price, which also includes a sales tax. For example, if the item’s wholesale cost is $5.00 and it’s markup is 100 percent, than the item’s retail price will be the marked up cost ($10.00) plus the sales tax (assume 6%), which would be $10.60). If an item’s wholesale cost is $10.00 and it’s markup is 50...
Write an Algorithm that asks the user to enter an address and print each part of...
Write an Algorithm that asks the user to enter an address and print each part of the address on a separate line. Example: Input 344 Rose Dr, Raeford, NC 28376 Output Street No.: 344 Street Name: Rose Dr City: Raeford State: North Carolina Zip Code: 28376 Hints: Deal with the address as a string. The address must contain two commas. The text before first comma contains the street number and street name separated by one or more white spaces. The...
Write a java simple document retrieval program that first asks the user to enter a single...
Write a java simple document retrieval program that first asks the user to enter a single term query, then goes through two docuements named doc1.txt and doc2.txt (provided with assignment7) to find which document is more relevant by calculating the frequency of the query term in each document. Output the conclusion to a file named asmnt7output.txt in the following format (as an example for query “java” and “problem”). The percentages in parenthese are respective supporting frequencies. java: doc1(6.37%) is more...
IN JAVA Write a complete program that asks the user to enter two real numbers from...
IN JAVA Write a complete program that asks the user to enter two real numbers from the console. If both numbers are positive print the product, if both numbers are negative print the quotient, otherwise print INVALID INPUT. Use a nested if; output should be to a dialog and console; use printf to format the console output (for real numbers specify the width and number of digits after the decimal). The output must be labeled. Follow Java conventions, indent your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT