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









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... - ad-authenticator version 0.2.0 java library in your project. ADS
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... - ad-authenticator version 0.3.3 java library in your project. ADS
Java switch statement
Java switch statement  What restrictions are placed on the values of each case of a switch statement
switch Java Keyword
the switch case. Example to use the Switch keyword within a class in java... switch Java Keyword       The switch is a keyword defined in the java programming language. Keywords
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...Maven dependency for  com.ad-authenticator  - Version 1.0.0 of ad...-authenticator - ad-authenticator-sonar-plugin project have released the latest version
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
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
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
Switch case in java
will illustrate the use of switch case in java: import java.util.Scanner; public.... If we talk about the advantage of switch over if else then the same code could...Switch case in java In this section we will learn about switch case in java
Switch
statements. To avoid this we can use Switch statements in Java. The switch statement... 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
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
Maven dependency for com.braintreepayments - browser-switch version 1.0.0 is released. Learn to use browser-switch version 1.0.0 in Maven based Java projects
-switch version 1.0.0 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 1.0.0 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 0.1.1 is released. Learn to use browser-switch version 0.1.1 in Maven based Java projects
-switch version 0.1.1 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 0.1.1 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 1.1.3 is released. Learn to use browser-switch version 1.1.3 in Maven based Java projects
-switch version 1.1.3 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 1.1.3 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 1.1.1 is released. Learn to use browser-switch version 1.1.1 in Maven based Java projects
-switch version 1.1.1 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 1.1.1 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 0.2.0 is released. Learn to use browser-switch version 0.2.0 in Maven based Java projects
-switch version 0.2.0 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 0.2.0 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 0.1.6 is released. Learn to use browser-switch version 0.1.6 in Maven based Java projects
-switch version 0.1.6 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 0.1.6 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 0.1.4 is released. Learn to use browser-switch version 0.1.4 in Maven based Java projects
-switch version 0.1.4 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 0.1.4 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser_switch version 0.1.0 is released. Learn to use browser_switch version 0.1.0 in Maven based Java projects
_switch version 0.1.0 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser_switch version 0.1.0 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 0.1.2 is released. Learn to use browser-switch version 0.1.2 in Maven based Java projects
-switch version 0.1.2 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 0.1.2 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 1.1.4 is released. Learn to use browser-switch version 1.1.4 in Maven based Java projects
-switch version 1.1.4 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 1.1.4 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 1.1.2 is released. Learn to use browser-switch version 1.1.2 in Maven based Java projects
-switch version 1.1.2 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 1.1.2 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 1.1.0 is released. Learn to use browser-switch version 1.1.0 in Maven based Java projects
-switch version 1.1.0 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 1.1.0 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 0.1.7 is released. Learn to use browser-switch version 0.1.7 in Maven based Java projects
-switch version 0.1.7 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 0.1.7 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 0.1.5 is released. Learn to use browser-switch version 0.1.5 in Maven based Java projects
-switch version 0.1.5 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 0.1.5 java library in your project. ADS_TO_REPLACE_2 Now
Maven dependency for com.braintreepayments - browser-switch version 0.1.3 is released. Learn to use browser-switch version 0.1.3 in Maven based Java projects
-switch version 0.1.3 ) in their Java project if it is based on Maven and Gradle...: Create or use a Maven project First of all you have to create a new Java project... - browser-switch version 0.1.3 java library in your project. ADS_TO_REPLACE_2 Now
switch functions - Java Beginners
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... friend, This is running code, switch option using in javaSctipt
Switch Statement example in Java
for implementing the switch statement. Here, you will learn how to use the switch statement... for understanding more about the switch statement in Java. The following java... Switch Statement example in Java    
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.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.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...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.3 Now the next step is to use... to use the  io.github.thebesteric.framework.switchlogger - switch-logger-core
Maven dependency for io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.1 is released. Learn to use switch-logger-core version 1.0.1 in Maven based Java projects
( io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.1 ) in their Java project...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.1 Now the next step is to use... to use the  io.github.thebesteric.framework.switchlogger - switch-logger-core
Maven dependency for io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.0-RELEASE is released. Learn to use switch-logger-core version 1.0.0-RELEASE in Maven based Java projects
- switch-logger-core version 1.0.0-RELEASE in Java projects. Follow the step by step... of io.github.thebesteric.framework.switchlogger - switch-logger-core in your Maven/Gradle project. Step 1: Create or use...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.0-RELEASE java library
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...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.4 Now the next step is to use... to use the  io.github.thebesteric.framework.switchlogger - switch-logger-core
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...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.2 Now the next step is to use... to use the  io.github.thebesteric.framework.switchlogger - switch-logger-core
Maven dependency for io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.1 is released. Learn to use switch-logger-core version 1.0.1 in Maven based Java projects
( io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.1 ) in their Java project...; io.github.thebesteric.framework.switchlogger - switch-logger-core version 1.0.1 Now the next step is to use... to use the  io.github.thebesteric.framework.switchlogger - switch-logger-core
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 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
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
Switch Statement in java 7
' and use break to jump out the switch block. In the same way it works... Switch Statement in java 7 This tutorial describes the if statement in java 7. This is one kind of decision making statement. Switch Statements
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...: import java.util.*; import java.text.*; class Shop{ public String item; public
Java Switch Statement
Java Switch Statement       In java, switch is one of the control statement which turns the normal flow control of the program as per conditions. It's like if-else statement but it can
Pkg Inheritance under same pkg - Java Beginners
Pkg Inheritance under same pkg   Hi Friends I want to extend the Predefined ( . java File ) class in a another inherited class( .java file ) in the same pkg If this is allowed in the same pkg, please tell me how
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
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

Ads