68 355
Assignments Done
98,7%
Successfully Done
In November 2018

Answer to Question #43385 in Java | JSP | JSF for Shaban

Question #43385
XYZ Supermarket wants a program that will prompt for the product code, pricing code, price and quantity of an article. Your program is then to calculate a discount rate according to the pricing code. The program will also ask the address and if the user wants overnight shipping. Regular shipping for items total under $100 is $20.00; for items total $100 or more shipping is $30.00. For overnight delivery add $50.00. Print to the screen all the entered data of the article, the discount amount and the new discounted price
Expert's answer
import java.io.*;
public class XYZSupermarket {
 static String productCode = null;
  static String pricingCode = null; 
  static Double price; 
  static int quantityOfArticle;
  static String address = null;
static boolean nightshipping ;
 static void enterData() throws IOException
 {
 BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
  System.out.println("Enter the product code:");
 productCode = br.readLine();
System.out.println("Enter the pricing code:");
String pricingCode = br.readLine();
System.out.println("Enter the price:");
price = Double.parseDouble(br.readLine());
System.out.println("Enter the quantity of an article:");
quantityOfArticle = Integer.parseInt(br.readLine()) ; 
System.out.println("Enter the adress:");
address = br.readLine(); 
 checkingForOvernightShipping();
 }
static void  checkingForOvernightShipping() throws IOException
{
System.out.println("Enter Y if you want overnight shipping or N if you dont want");
 BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
String temp = br.readLine();  
if (temp.equals("Y")||temp.equals("y")) 
  nightshipping = true;
 else 
  nightshipping = false;
}
 static void outputData() 
 {
  System.out.println("Product code is "+productCode);
 System.out.println("Pricing code is "+pricingCode);
 System.out.println("Price is "+price+" $");
 System.out.println("Quantity of an article is "+quantityOfArticle);
 System.out.println("Adress is "+address);
 calculatingPrice();
}
 static void calculatingPrice() 
 {
 price*=quantityOfArticle;
 if (price<100)
 {
 price += 20.00; 
 System.out.println("Regular shipping is 20.00 $");
 }
 else
 {
 price += 30.00; 
 System.out.println("Regular shipping is 30.00 $");
 }
 if(nightshipping)
 {
price += 50.00;
System.out.println("Overnight delivery is $50.00 $");
 }
System.out.println("The total discounted price " +price);
}
 public static void main(String[] args) throws IOException {
enterData();
outputData();
 
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions