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
Maven dependency for com.ad-authenticator - ad-authenticator version 0.2.0 is released. Learn to use ad-authenticator version 0.2.0 in Maven based Java projects
library is 0.2.0. Developer can use this version ( com.ad-authenticator - ad... 1: Create or use a Maven project First of all you have to create a new Java...Maven dependency for  com.ad-authenticator  - Version 0.2.0 of ad
Maven dependency for com.ad-authenticator - ad-authenticator version 0.3.3 is released. Learn to use ad-authenticator version 0.3.3 in Maven based Java projects
library is 0.3.3. Developer can use this version ( com.ad-authenticator - ad... 1: Create or use a Maven project First of all you have to create a new Java...Maven dependency for  com.ad-authenticator  - Version 0.3.3 of ad
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
Maven dependency for com.ad-authenticator - ad-authenticator-sonar-plugin version 1.0.0 is released. Learn to use ad-authenticator-sonar-plugin version 1.0.0 in Maven based Java projects
-authenticator - ad-authenticator-sonar-plugin library is 1.0.0. Developer can use...; com.ad-authenticator - ad-authenticator-sonar-plugin version 1.0.0 java...Maven dependency for  com.ad-authenticator  - Version 1.0.0 of ad
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   
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
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.4 is released. Learn to use switch-logger-core version 1.0.4 in Maven based Java projects
( io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.4 ) in their Java project... - switch-logger-core version 1.0.4 Now the next step is to use the latest...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.4 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
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
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
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
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
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
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
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
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 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
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
C Break with Switch statement
C Break with Switch statement       In this section, you will learn how to use break statement with Switch-Case in C. The switch case statements allows to control complex
Example of a class variable (static variable)
are created from the same class, each instance has its own copy of class... can call class variable directly inside the main method. To see the use... class and call the static variable of the class. In the same way now make a second
Class names don't identify a class - Java Tutorials
declaration is different. The general way to use this class at run time instead... This is a First Class But suppose a situation where you wish to use the make an instance of both the classes at the same time. Generally you can not do
Java inner class and static nested class
Java inner class and static nested class  Java inner class and static nested class
The Switch statement
. To avoid this we can use Switch statements in Java. The switch statement is used... of a variable or expression. The switch statement in Java is the best way to test... a statement following a switch statement use break statement within the code block
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
Create SpreadSheet same as excel using java applet
Create SpreadSheet same as excel using java applet  Hi Ji, May i know to create new excel sheet using java Applet
Create SpreadSheet same as excel using java applet
Create SpreadSheet same as excel using java applet  Hi Ji, May i know to create new excel sheet using java Applet
Java class in JSP
Java class in JSP          To use a Java class method in jsp first we need.... At last use the instance of the class to access the methods of the java file
Java Class Size
Java Class Size  How to determine size of java class
What is Calendar class in Java?
What is Calendar class in Java?  Hi, What is Calendar class in Java? I want to learn about this class to make use of it in Java programs. Thanks   Hi, java.util.Calendar is an abstract class in Java and its static
Class and method question, Java?
Class and method question, Java?  Consider a Java class that you could use to get an acceptable integer value from the user. An object of this class... getValue b. implement the class in Java c. Write some Java statements that test
Java Class Question?
Java Class Question?  b.Write an application that prompts the user... the user enters a selection.   import java.util.*; class Application...=input.next().charAt(0); switch(ch){ case 'S
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
class method in java
class method in java  How to write a class method in Java?   You must read Java - Class, Object and Methods in Java

Ads