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

Java Programming : Email username generator Write an application that asks the user to enter first...
Java Programming : Email username generator Write an application that asks the user to enter first name and last name. Generate the username from the first five letters of the last name, followed by the first two letters of the first name. Use the .toLowerCase() method to insure all strings are lower case. String aString = “Abcd” aString.toLowerCase(); aString = abcd Use aString.substring(start position, end position + 1) aString.substring(0, 3) yields the first 3 letters of a string If the...
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...
In java, write a program that asks the user to enter a character. Then pass the...
In java, write a program that asks the user to enter a character. Then pass the character to the following methods. isVowel() – returns true if the character is a vowel isConsonant() – returns true if the character is a consonant changeCase() – if the character is lower case then change it to upper case and if the character is in upper case then change it to lower case. (return type: char) Example output is given below: Enter a character...
JAVA Write a Java console application that prompts the user to enter the radius of a...
JAVA Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Programmer Notes Write and document your program per class coding conventions. Add an instance variable double radius. Generate its get/set methods. Manually type the methods getDiameter(), getCircumference(), and getArea()....
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...
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...
USING THE SWITCH STATEMENT - Write a java program that asks the user to enter the...
USING THE SWITCH STATEMENT - Write a java program that asks the user to enter the number of their favorite month of the year – obviously, that would be 1 – 12. Write a switch statement that takes the number and converts it to the fully spelled out name [ex. 3 would be MARCH] . Be sure to build in error message to catch any invalid data entries such as 0 or 13 etc. Print out the number that was...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT