Question

Question 2: write a java program    A Hypermarket makes an offer for its customers according...

Question 2: write a java program   

A Hypermarket makes an offer for its customers according to the number of items to be bought as follows:

Number of purchased items

Discount percentage

Less than 25

2.5%

25 – 50

5.0%

51 – 100

6.25%

Greater than 100

7.5%

The hypermarket also adds 2% city taxes to the purchases after the sale discount.

  1. Reads from the user the number of items to be purchased and the item price.
  2. Calculates and prints the original purchase cost.
  3. Calculates and prints the discount amount.
  4. Calculates and prints the new purchase cost after computing the discount.

Net Purchase Amount = Purchase amount after discount + City Tax

Homework Answers

Answer #1

//importing package which contains Scanner class
import java.util.*;
//class
class Market
{
//main function
public static void main(String args[])
{
int n;
double price,discount,total_cost;
//creating Scanner class object
Scanner s=new Scanner(System.in);
//asking user to enter number of items
System.out.print("Enter the number of items to be purchased: ");
//storing integer input in n
n=s.nextInt();
//asking user to enter item price
System.out.print("Enter the item price: ");
//storing double input in price
price=s.nextDouble();
//calculate and print original purchase cost for n items each having cost as price
total_cost=price*n;
System.out.println("Original Purchase cost: "+total_cost);
//calculate the discount amount
//the below if else control statements are written according to the table given in question
if(n<25)
discount=2.5*(total_cost)/100;
else if(n>=25 && n<=50)
discount=5.0*(total_cost)/100;
else if(n>=51 && n<=100)
discount=6.25*(total_cost)/100;
//case when n>100
else
discount=7.5*(total_cost)/100;
//print the discount amount
System.out.println("Discount amount: "+discount);

//calculate new purchase cost after subtracting discount
total_cost=total_cost-discount;
//printing cost after discount
System.out.println("New purchase cost after discount: "+total_cost);
//calculate net purchase amount after adding city tax of 2%
total_cost=total_cost+(2*total_cost)/100;
//printing cost after adding city tax
System.out.println("Net purchase amount after adding city tax: "+total_cost);
}


}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
WRITE A JAVA PROGRAM 1. Assignment Description Write a stock transaction program that calculates a customer's...
WRITE A JAVA PROGRAM 1. Assignment Description Write a stock transaction program that calculates a customer's profit (or loss) within a certain period of time. 1) First, the program need to get user's name, the stock's code, number of shares and the price he/she purchased the stock, it also asks the user for the price he/she sold the stock later on. The program then compute the following: The amount of money the customer paid for the stock. The amount of...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
***Programming language is Java. After looking at this scenario please look over the requirements at the...
***Programming language is Java. After looking at this scenario please look over the requirements at the bottom (in bold) THIS IS ALL THAT WAS PROVIDED. PLEASE SPECIFY ANY QUESTIONS IF THIS IS NOT CLEAR (don't just say more info, be specific)*** GMU in partnership with a local sports camp is offering a swimming camp for ages 10-18. GMU plans to make it a regular event, possibly once a quarter. You have been tasked to create an object-oriented solution to register,...
step by step solution for the below question please Flag this Question Question 11 pts What...
step by step solution for the below question please Flag this Question Question 11 pts What is the difference between positive economics and normative economics? Group of answer choices Positive economics deals with dynamic systems, while normative economics focuses on static systems. Normative economics deals with how the world actually works, whereas positive economics focuses on what people ought to do. Positive economics requires making value judgments, while normative economics relies solely on factual statements. Normative economics applies in cases...
Complete the journal entries for each of the transactions. Transaction Description of transaction 01. June 1:...
Complete the journal entries for each of the transactions. Transaction Description of transaction 01. June 1: Byte of Accounting, Inc. issued 2,580 shares of its common stock to Jeremy after $25,200 in cash and computer equipment with a fair market value of $36,720 were received. 02. June 1: Byte of Accounting, Inc. issued 2,488 shares of its common stock after acquiring from Courtney $46,800 in cash, computer equipment with a fair market value of $12,000 and office equipment with a...
1-25 True or False 1. Sales revenue is an inflow of assets. 2. The three distinct...
1-25 True or False 1. Sales revenue is an inflow of assets. 2. The three distinct types of cost to a manufacturer are direct materials, direct labor, and manufacturing overhead.                       3. Sales Returns and Allowances is a contra-asset account. 4. Like sales revenue, cost of goods sold represents an inflow of assets. 5. With the periodic inventory system the inventory account is updated after each sale or purchase. 6. When merchandise is sold FOB shipping point, the buyer is responsible...
Design a FSM for a Vending Machine In this task, you will design a FSM for...
Design a FSM for a Vending Machine In this task, you will design a FSM for a simple (albeit strange) vending machine of office supplies. The vending machine sells three possible items, each at a different cost: Item Cost Pencil 10 cents Eraser 20 cents Pen 30 cents The vending machines accepts nickels (worth 5 cents), dimes (worth 10 cents), and quarters (worth 25 cents). Physically, it is only possible to insert a single coin at a time. The vending...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT