Purchase Amount | Discount | |
Mill Cloth | Handloom items | |
| | |
0 - 100 | - | 5.00% |
| | |
101-200 | 5.00% | 7.50% |
| | |
201-300 | 7.50% | 10.00% |
| | |
Above 300 | 10.00% | 15.00% |
Write a program using switch and if statements to compute the net amount to be paid by a customer.
import java.util.*;
public class CalculateNetAmount
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.print("Enter the item type(M/H)");
char c=scan.nextLine().toUpperCase().toCharArray()[0];
System.out.print("Enter the cost:");
double cost=scan.nextDouble();
double dis=discount(c,cost);
double netAmt=cost-dis;
System.out.println("The net paid amount="+netAmt);
}
public static double discount(char typ, double cost) {
double dis = 0;
double rate = 0;
switch (typ) {
case 'M':
if (cost > 100 && cost <= 200) {
rate = 5;
} else if (cost > 200 && cost <= 300) {
rate = 7.5;
} else if (cost > 300) {
rate = 10;
}
break;
case 'H':
if (cost > 0 && cost <= 100) {
rate = 5;
} else if (cost > 100 && cost <= 200) {
rate = 7.5;
} else if (cost > 200 && cost <= 300) {
rate = 10;
} else if (cost > 300) {
rate = 15;
}
break;
}
dis = cost * rate / 100;
return dis;
}
}
public class CalculateNetAmount
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.print("Enter the item type(M/H)");
char c=scan.nextLine().toUpperCase().toCharArray()[0];
System.out.print("Enter the cost:");
double cost=scan.nextDouble();
double dis=discount(c,cost);
double netAmt=cost-dis;
System.out.println("The net paid amount="+netAmt);
}
public static double discount(char typ, double cost) {
double dis = 0;
double rate = 0;
switch (typ) {
case 'M':
if (cost > 100 && cost <= 200) {
rate = 5;
} else if (cost > 200 && cost <= 300) {
rate = 7.5;
} else if (cost > 300) {
rate = 10;
}
break;
case 'H':
if (cost > 0 && cost <= 100) {
rate = 5;
} else if (cost > 100 && cost <= 200) {
rate = 7.5;
} else if (cost > 200 && cost <= 300) {
rate = 10;
} else if (cost > 300) {
rate = 15;
}
break;
}
dis = cost * rate / 100;
return dis;
}
}
Responses
0 Respones to "35. A cloth showroom has announced the following seasonal discounts on purchase of items:"
Post a Comment