paper roll as per the following criteria:
Length of the paper Dealer Retailer
Up to 10 metres 10% 8%
11 metres and up to 20 metres 15% 10%
More than 20 metres 20% 15%
Write a program to input the length of paper roll and the amount of purchase. Use menu driven approach
having choices (D) for dealer and (R) for retailer to find and print the amount to be paid to the company after
discount.
For an inappropriate choice, display “Wrong Choice”.
import java.util.*;
public class Assignment_5
{
public static void main(String args[])
{
String ch = "";
int Pay = 0;
Scanner sc = new Scanner(System.in);
System.out.print("User menu");
System.out.println("D for Dealer");
System.out.println("R for Retailer");
System.out.print("Enter your Choice");
ch = sc.nextLine();
System.out.print("Enter the lenght of paper roll");
int len = sc.nextInt();
System.out.print("Enter the amount of purchase");
int pur = sc.nextInt();
switch(ch)
{
case "D":{
if(len > 0 && len <= 10)
{
Pay = pur-((pur * 10) / 100);
}
else if(len > 10 && len <= 20)
{
Pay = pur-((pur * 15) / 100);
}
else if(len > 20)
{
Pay = pur-((pur * 20) / 100);
}
System.out.println("Amount to be paid: " + Pay);
}
break;
case "R" :{
if(len > 0 && len <= 10)
{
Pay = pur-((pur * 8) / 100);
}
else if(len > 10 && len <= 20)
{
Pay = pur-((pur * 10) / 100);
}
else if(len > 20)
{
Pay = pur-((pur * 15) / 100);
}
System.out.println("Amount to be paid: " + Pay);
}
break;
default : System.out.println("Wrong Choice");
}
}
}
{
public static void main(String args[])
{
String ch = "";
int Pay = 0;
Scanner sc = new Scanner(System.in);
System.out.print("User menu");
System.out.println("D for Dealer");
System.out.println("R for Retailer");
System.out.print("Enter your Choice");
ch = sc.nextLine();
System.out.print("Enter the lenght of paper roll");
int len = sc.nextInt();
System.out.print("Enter the amount of purchase");
int pur = sc.nextInt();
switch(ch)
{
case "D":{
if(len > 0 && len <= 10)
{
Pay = pur-((pur * 10) / 100);
}
else if(len > 10 && len <= 20)
{
Pay = pur-((pur * 15) / 100);
}
else if(len > 20)
{
Pay = pur-((pur * 20) / 100);
}
System.out.println("Amount to be paid: " + Pay);
}
break;
case "R" :{
if(len > 0 && len <= 10)
{
Pay = pur-((pur * 8) / 100);
}
else if(len > 10 && len <= 20)
{
Pay = pur-((pur * 10) / 100);
}
else if(len > 20)
{
Pay = pur-((pur * 15) / 100);
}
System.out.println("Amount to be paid: " + Pay);
}
break;
default : System.out.println("Wrong Choice");
}
}
}
No comments:
Post a Comment