Ramesh went to a general Store and picked two items of x and y prices.Write a java program to calculate the total amount for Ramesh to pay.Sample Test Case:Enter x value: 10Enter y value: 20Sum: 30Sample Test Cases
Question
Ramesh went to a general Store and picked two items of x and y prices.Write a java program to calculate the total amount for Ramesh to pay.Sample Test Case:Enter x value: 10Enter y value: 20Sum: 30Sample Test Cases
Solution
Here is a simple Java program that calculates the total amount for Ramesh to pay:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter x value: ");
int x = scanner.nextInt();
System.out.println("Enter y value: ");
int y = scanner.nextInt();
int sum = x + y;
System.out.println("Sum: " + sum);
}
}
This program works as follows:
-
It imports the Scanner class, which is used to get user input.
-
It defines a
mainmethod, which is the entry point for any Java program. -
Inside the
mainmethod, it creates a new Scanner object that reads from the standard input stream (System.in). -
It prompts the user to enter the value of
xand reads the input usingscanner.nextInt(). -
It does the same for the value of
y. -
It calculates the sum of
xandyand stores the result in thesumvariable. -
Finally, it prints the sum to the standard output stream (System.out).
Similar Questions
Linda is managing a small business and wants to calculate the total revenue based on the sales of two products. The price of the first product is 25 rupees, and the price of the second product is 40 rupees. Write a program that takes the quantity sold for each product as input and outputs the total revenue using arithmetic operators
write a java program to define a class Item having item namepricequantityfind the total cost of the itemuse accept method to get the data from the user and toString method to display the detailscreate two objects and display the name of the item which is ordered more quantitydisplay total amount of items purchased.edited 10:37 AM
Problem StatementMaria loves shopping and is curious to know the total cost of her favorite items. She intends to purchase t items, each priced at p rupees, with a progressive increase of 5 rupees for every subsequent item.Write a program that takes the price of one item (p) and the number of items (t) as input, calculates the total cost using the formula (t/2) * (2p + (t-1) * 5), and displays the result.Input format :The first line of input consists of a float value p, representing the price of an item.The second line of input consists of an integer t, representing the number of items.Output format :The output displays "Rs. " followed by a float value, representing the total cost in rupees, rounded off to two decimal places.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:10.0 ≤ p ≤ 1000.01 ≤ t ≤ 100Sample test cases :Input 1 :10.03Output 1 :Rs. 45.00Input 2 :720.056Output 2 :Rs. 48020.00
Develop a Java program for a ticket pricing system. Prompt the user to enter their age and the type of ticket they want to purchase (1 for regular, 2 for VIP). Use if-then-else statements to calculate the ticket price based on the following criteria:Regular Ticket Prices:Age 0-5: FreeAge 6-12: $10Age 13-18: $15Age 19 and above: $20VIP Ticket Prices:Age 0-5: $5Age 6-12: $15Age 13-18: $20Age 19 and above: $30Display the calculated ticket price to the user. Ensure that your program handles invalid input, such as negative age or an invalid ticket type.
Assume that J-Mart uses a perpetual weighted average inventory system. During the period, it had two sales. Calculate the average cost per unit on hand as of June 8 when it made its first sale. DateItemUnits/CostJun 1Beginning Inventory10 @ $12Jun 5Purchase10 @ $15Jun 8Sale6 unitsJun 28Purchase10 @ $18Jun 30Sale8 unitsMultiple choice question.$15/unit$33/unit$13.50/unit$10/unit
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.