Use if, if else,for,while,do wile ad switch in same Java Class

Use if, if else,for,while,do wile ad switch in same Java Class

hi how to use if, if else,for,while,do wile ad switch in same class? very urgent..

View Answers

April 11, 2012 at 4:51 PM

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() {
return total;
}
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);
int menu = 0;
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.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();
switch(menu) {
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;
list.add(new Shop("T Shirt",q1,p1,d1,t1));
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;
list.add(new Shop("Silk sari",q2,p2,d2,t2));
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;
list.add(new Shop("Baba suit",q3,p3,d3,t3));
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;
list.add(new Shop("Trousers",q4,p4,d4,t4));break;
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);
}
}

April 11, 2012 at 4:53 PM

Please visit the following link:

Calculator in java swing

Ads









Related Tutorials/Questions & Answers:
Use if, if else,for,while,do wile ad switch in same Java Class
Use if, if else,for,while,do wile ad switch in same Java Class  hi how to use if, if else,for,while,do wile ad switch in same class? very urgent..   import java.util.*; import java.text.*; class Shop{ public String
java do wile - Java Server Faces Questions
java do wile  Write a program that asks the user to enter two words. The program then prints out both words on one line. The words will be separated...*; class WordString { public static void main(String[] args) throws
Advertisements
Switch Statement with Strings in Java
Switch Statement with Strings in Java  Switch Statement with Strings in Java
switch Java Keyword
. Example to use the Switch keyword within a class in java programming language... switch Java Keyword       The switch is a keyword defined in the java programming language. Keywords
Can I have multiple main() methods in the same class?
Can I have multiple main() methods in the same class?  Hi, Can I have multiple main() methods in the same class?   Hi, No, We cann't use multiple main() method within the same class. If we do this then the program
Top 5 Ad Networks which can be used with Google Adsense
Top 5 Ad Networks which can be used with Google Adsense - Use the ads from these Ad Networks on the same web pages on your website. This article... beats any other networks. You can use the other ad networks which
Switch case in java
will illustrate the use of switch case in java: import java.util.Scanner; public... the advantage of switch over if else then the same code could be written...Switch case in java In this section we will learn about switch case in java
ModuleNotFoundError: No module named 'wile'
ModuleNotFoundError: No module named 'wile'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'wile' How to remove the ModuleNotFoundError: No module named 'wile' error
Class and interface in same file and accessing the class from a main class in different package
Class and interface in same file and accessing the class from a main class... a class named CantFly in same file. A main method CheckAnimal.java. Below... pattern videos on YouTube, however I have a small doubt on some basic Java concept
Class and interface in same file and accessing the class from a main class in different package
Class and interface in same file and accessing the class from a main class... a class named CantFly in same file. A main method CheckAnimal.java. Below... pattern videos on YouTube, however I have a small doubt on some basic Java concept
Switch Statement example in Java
for implementing the switch statement. Here, you will learn how to use the switch statement... more about the switch statement in Java. The following java program tells you... Switch Statement example in Java    
Are J2EE and Java Advanced the same?
Are J2EE and Java Advanced the same?  Hi, I am checking J2EE and Advanced Java. Are J2EE and Java Advanced the same? Thanks   Hi, J2EE is now renamed to JEE in latest version of Java platform, which is Specification
Java - The switch construct in Java
same as If-Else construct. This is the difference between Switch and If-Else... choices are available then we generally use the If-Else construct otherwise Switch... Java - The switch construct in Java   
Maven dependency for io.github.thebesteric.framework.switchlogger - switch-logger-core version 0.0.1 is released. Learn to use switch-logger-core version 0.0.1 in Maven based Java projects
( io.github.thebesteric.framework.switchlogger - switch-logger-core version 0.0.1 ) in their Java project... - switch-logger-core version 0.0.1 Now the next step is to use the latest...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 0.0.1 java library
Maven dependency for io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.3 is released. Learn to use switch-logger-core version 1.0.3 in Maven based Java projects
( io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.3 ) in their Java project... - switch-logger-core version 1.0.3 Now the next step is to use the latest...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.3 java library
Maven dependency for io.github.thebesteric.framework.switchlogger - switch-logger-core version 0.0.2 is released. Learn to use switch-logger-core version 0.0.2 in Maven based Java projects
( io.github.thebesteric.framework.switchlogger - switch-logger-core version 0.0.2 ) in their Java project... - switch-logger-core version 0.0.2 Now the next step is to use the latest...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 0.0.2 java library
Maven dependency for io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.2 is released. Learn to use switch-logger-core version 1.0.2 in Maven based Java projects
( io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.2 ) in their Java project... - switch-logger-core version 1.0.2 Now the next step is to use the latest...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.2 java library
Switch Case in Java
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 version of Java did not support String in switch/case. Switch statements works
Switch Statement in java 7
Switch Statement in java 7 This tutorial describes the if statement in java 7. This is one kind of decision making statement. Switch Statements... to jump out the switch block. In the same way it works for day value 2,3..up
different output trying to execute same java code
different output trying to execute same java code  i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding... there is different output trying to execute same java code
why we use abstract class in java?
why we use abstract class in java?  what is the the purpose of abstract class.Give example when to use abstract and when use interface
Java Switch Statement
Java Switch Statement       In java, switch is one of the control statement which turns the normal flow... more about the switch statement click on:   http:/www.roseindia.net/java
3 queries on java class
3 queries on java class  Hey. I need to do 3 queries on same class ( JAVA) One is to populate the combobox, the another one to populate tje jlist and the last one to use on button to open a file from database (BLOB) Can some
different output trying to execute same java code
different output trying to execute same java code  i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding... " portList : false" Why there is different output trying to execute same java
different output trying to execute same java code
different output trying to execute same java code  i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding... " portList : false" Why there is different output trying to execute same java
java class
java class  write a java program to display a msg "window closing" when the user attempts to close the window.(a) create a window class (b) create frame within the window class (c) extends window adapter class to display the msg
java class
java class  please send me the answer of the question which i have send according of java class assoon as possible . Write a java program to display.... a. Create a window class. b. Create frame within the window class. c. Extend
Switch Statement
Switch Statement  How we can use switch case in java program ?   Note:-Switch case provides built-in multiway decision statement.It... java.io.IOException; import java.io.InputStreamReader; public class SwitchTest
Fields in java class
Fields in java class      ... will access by the class, subclass or classes in the same package. Private: This type of field can be access by the same elements of the class. Package
Use of Local Inner class
. The inner class Get Even Integer is same as Java iterators,The work of Get Even... Use of Local Inner class       The Java language enables you to define a class inside another
Abstract class and interface in Java
Abstract class and interface in Java  What is the difference between abstract class and interfaces in Java?   Differences between an interface and an abstract class: At the same time multiple interfaces can

Ads