# using if and switch stmt

vanshi
using if and switch stmt
Posted in : Java Beginners
A cloth showroom has announced the following discounts on purchase of items
T Shirt - 10% discount
Silk sari- 30% discount
Baba suit- 40% discount
Trousers - 15% discount

cost of the items can be assumed.
Write a program using "switch and if statement" to compute net amount to be paid by a customer.

May 12, 2010 at 12:48 PM

Hi Friend,

Try the following code:
import java.util.*;
import java.text.*;
class Shop{
public String item;
public int quantity;
public double price;
public double discount;
public double total;

public Shop(){}
public Shop(String item,int quantity, double price,double discount,double total) {
super();
this.item=item;
this.quantity= quantity;
this.price = price;
this.discount=discount;
this.total=total;
}
public String getItem() {
return item;
}
public int getQuantity() {
return quantity;
}
public double getPrice() {
return price;
}
public double getDiscount() {
return discount;
}
public double getTotal() {
}
public static void main(String[] args) throws Exception {
double sum=0.0;
DecimalFormat df = new DecimalFormat("##%");
List<Shop> list = new ArrayList<Shop>();
Scanner scan = new Scanner(System.in);
System.out.println("Cloth Showroom");
System.out.println();
System.out.println("1. T Shirt");
System.out.println("2. Silk sari");
System.out.println("3. Baba suit");
System.out.println("4. Trousers ");
System.out.println("5. Exit");

boolean quit = false;
do{
System.out.println();
case 1:
System.out.print("Quantity: ");
int q1 = scan.nextInt();
System.out.print("Price: ");
double p1 = scan.nextDouble();
double d1=0.10;
double t1=(p1-(d1*p1))*q1;
break;
case 2:
System.out.print("Quantity: ");
int q2 = scan.nextInt();
System.out.print("Price: ");
double p2 = scan.nextDouble();
double d2=0.30;
double t2=(p2-(d2*p2))*q2;
break;
case 3:
System.out.print("Quantity: ");
int q3 = scan.nextInt();
System.out.print("Price: ");
double p3 = scan.nextDouble();
double d3=0.40;
double t3=(p3-(d3*p3))*q3;
break;
case 4:
System.out.print("Quantity: ");
int q4 = scan.nextInt();
System.out.print("Price: ");
double p4 = scan.nextDouble();
double d4=0.15;
double t4=(p4-(d4*p4))*q4;
case 5:
quit = true;
System.out.println("Items Quantity Price T.Price Discount(%) Total");
for (Shop s : list){
System.out.println(s.getItem()+" " +s.getQuantity()+" "+s.getPrice()+" "+(s.getQuantity()*s.getPrice())+" "
+df.format((s.getDiscount()))+" " +s.getTotal());
sum+=s.getTotal();
}
System.out.println("Total= "+sum);

break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}
Thanks

using if and switch stmt - Java Beginners
using if and switch stmt  A cloth showroom has announced... be assumed. Write a program using "switch and if statement" to compute net amount...(); switch(menu) { case 1: System.out.print("Quantity: "); int q1 = scan.nextInt
using switch,break and for loop
using switch,break and for loop  generate a 10 digit number and display the length of longest increasing series
using switch and break
using switch and break  generate a 10 digit number and display the length of longest increasing series
using switch case
using switch case  Define a class MENU to perform the following operation depending upon the users choice using switch case 1)print square root... choice: "); int choice=input.nextInt(); switch(choice
change color of back ground using switch
change color of back ground using switch   how to change back ground color according to day using switch case
Write a java program to display the season given the month using switch case
Write a java program to display the season given the month using switch case  Write a java program to display the season given the month using switch case
core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases  How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings
Switch
on the value of week, using the switch statement. class ... Switch       Sometimes it becomes cumbersome to write lengthy programs using if and if-else
Find Capital using Switch-Case statement
Find Capital using Switch-Case statement In this Java Tutorial section, we are going to find the capital of our states using Switch-Case statement. For this, we have created two arrays i.e. array of states and array of capitals. Then we
switch statement
switch statement   i want to write a java program that computes Fibonacci,factorial,string reversal and ackerman using switch case to run as a single program
Showing Error for Prepared stmt in a jsp
Showing Error for Prepared stmt in a jsp  i hav a task to connect jsp to oracel database using preparestatement and gettin an error showin dat prepared statement obj cant be created pstmt is nt resloved here are the files
Showing Error for Prepared stmt in a jsp
Showing Error for Prepared stmt in a jsp  i hav a task to connect jsp to oracel database using preparestatement and gettin an error showin dat prepared statement obj cant be created pstmt is nt resloved here are the files
The Switch statement
of week, using the switch statement. class Switch{  ...Switch       Sometimes it becomes cumbersome to write lengthy programs using if and if-else statements
Switch Statement
Switch Statement  How we can use switch case in java program ?   Note:-Switch case provides built-in multiway decision statement.It...); switch(days){ case 1: System.out.println("Sunday
switch case
switch case  program to input 2 numbers and a choice.Using switch case we need to perform all the mathematical operation.Print a suitable error message if the choice is wrong
switch case
switch case  program to input 2 numbers and a choice.Using switch case we need to perform all the mathematical operation.Print a suitable error message if the choice is wrong
Switch databases
Switch databases  How do you inter-change between relational databases without code changes
Switch Case in Java
It is very difficult and lengthy to write programs using if-then and if-then-else statements. As switch statement allows in-numerous possible execution paths.... Switch statements with String cases are supported in Java SE 7 but the earlier
programes on switch
=input.nextInt(); switch(choice){ case 1
Switch Statement with Strings in Java
Switch Statement with Strings in Java  Switch Statement with Strings in Java
Java switch statement
Java switch statement  What restrictions are placed on the values of each case of a switch statement
switch case instead of if else
switch case instead of if else  How to write code in switch case instead of if else in Java
Switch case in Jsp page
using switch case in jsp page...Switch case in Jsp page  <table> <tr><td>Enter Distance :</td> <td><input type="text" name="dis"/></td>
Switch statement in PHP
Switch statement in PHP  HII, Explain about switch statement in PHP?   hello, Switch statement is executed line by line. PHP executes the statement only when the case statement matches the value of the switch
Switch case + condition??
Switch case + condition??  I try to use a switch case with condition but it doesn't display anything have look: ......public void commandAction...(); } } else { List down = (List)display.getCurrent(); switch
switch functions - Java Beginners
friend, This is running code, switch option using in javaSctipt...switch functions  I am writing a script for use in a computer based... your month of hire:") switch(n) { case(n="January"): document.write("Last
Switch Case - Java Interview Questions
Switch Case  int x=100000; switch(x) { case 100000: printf("Lacks"); } output= Lacks I want reason why x matches switch case although range for int is in between something -32678 to +32676. Plz give me ans quickly
Version of com.braintreepayments>browser-switch dependency
List of Version of com.braintreepayments>browser-switch dependency
Version of com.braintreepayments>browser_switch dependency
List of Version of com.braintreepayments>browser_switch dependency
switch Java Keyword
switch Java Keyword       The switch is a keyword defined in the java programming language. Keywords... in java programming language likewise the switch keyword indicates the following
Strings in Switch statement
Strings in Switch statement In this section, you will learn about strings in switch statements which is recently added feature in Java SE 7. Using JDK 7, you can pass string as expression in switch statement. The switch statement