Home Answers Viewqa Java-Beginners Use if, if else,for,while,do wile ad switch in same Java Class

 
 


viswanathan
Use if, if else,for,while,do wile ad switch in same Java Class
2 Answer(s)      a year and a month ago
Posted in : Java Beginners

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 Pages:
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
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
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
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 switch statement use break statement within the code block. However, its
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
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
Switch Statement example in Java
the switch statement. Here, you will learn how to use the switch statement in your java... the switch statement in Java. The following java program tells you for entering numbers... Switch Statement example in Java    
programes on switch
;import java.util.*; class Calculator { public static void main(String[] args..."); System.out.println("4 Division"); System.out.println("5 Exit"); do...=input.nextInt(); switch(choice){ case 1
switch CAPSLOCK button in my progranm...
switch CAPSLOCK button in my progranm...  I found that function... the capslocks switch button to become a button that i can switch it between on and off...*; import javax.swing.text.*; import javax.swing.border.*; public class CapslockKey
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 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
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
Class
. Constructor is the method which name is same to the class. But there are many difference... we assign the name of the method same as  class name. Remember... Class, Object and Methods     
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
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
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
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 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
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
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
switch Statement - Overview
Java Notes switch Statement - Overview...: statements // do these if expr != any above } Switch keywords.... Where to use switch? The ability of switch to choose
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
save switch data into database - Java Beginners
save switch data into database  switch(menu) { case 1://add... java.io.*; import java.util.*; class Student{ public int id; public String... String getName() { return name; } } public class RegistrationSystem { public
Java switch statement
Java switch statement  What restrictions are placed on the values of each case of a switch statement
Ad Copy,Ad Copy Services,Effective Copy for Ads,Ad Copy Outsourcing India
, not a logical one Your ad copy should dramatize the feeling your customers get while...Ad Copy Writing effective copy for ads, web pages, sales letters and other... begin writing. Do you want to generate inquiries (leads)? Do you want to get
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
Use of Throwable Class
Use of Throwable Class Throwable class is the super class of all the exceptional class and error class. Only objects of this class can be thrown & caught and handled by try-catch blocks. In java you can throw exception Object which
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
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
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
 Use of getBytesRead, getByteWritten and getRemaining method of Inflater class in java.
Use of getBytesRead, getByteWritten and getRemaining method of Inflater class in java. In this tutorial, we will discuss about getBytesRead(), getByteWritten() and getRemaining() method of Inflater class. The Inflater class provide
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
Switch case + condition??
Switch case + condition??  I try to use a switch case with condition...(); } } else { List down = (List)display.getCurrent(); switch...("Buy")){ buy( ); }else if ( label.equals("Sell
Displaying the same image in a JPanel and using scroll - HELP - Java Beginners
Displaying the same image in a JPanel and using scroll - HELP  I hope...; import java.awt.Color; import javax.swing.text.*; public class AAAA extends..., BorderLayout.CENTER); setVisible(true); } class WindowCatcher extends
local host sharing on same network compute
local host sharing on same network compute  i have an desktop bill application on wamp and i want to use it on other computer on same network . computer connected with hub or switch
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
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
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... value of a number(in decimals) 4)Quit   import java.util.*; class Menu
java class - Java Interview Questions
java class  What is the speciality of class? what is the use... having same name,same parameters and same return types of a super class in its subclass. For ex- class A { int i; A(int a, int b) { i = a+b; } void add
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
validate jtextfield in two different class use keylistener
validate jtextfield in two different class use keylistener  validate jtextfield in java swing will use two class, design part in one class and method calling in one class will use Keylisteners or change listeners
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... java.util.*; public class FindCapital { public static void main
Use of hashCode() method of LongBuffer class in java.
Use of hashCode() method of LongBuffer class in java. In this tutorial, we will see the use of hashCode() method of LongBuffer class in java. LongBuffer API: The java.nio.LongBuffer class extends java.nio.Buffer class
Use of hasCode method of FloatBuffer class in java.
Use of hashCode method of FloatBuffer class in java. In this tutorial, we will see the use of hashCode() method of FloatBuffer class in java. FloatBuffer API: The java.nio.FloatBuffer class extends java.nio.Buffer class
Use of getInt() method of ByteBuffer class in java.
Use of getInt() method of ByteBuffer class in java.  In this tutorial, we... of ByteBuffer class. ByteBuffer API: The java.nio.ByteBuffer class extends java.nio.Buffer class. It provides the following methods: Return
Use of getChar method of ByteBuffer Class in java.
Use of getChar method of ByteBuffer Class in java. In this tutorial, we will discuss the use of getChar() method of ByteBuffer class to fetch... of ByteBuffer class write bytes into buffer, and the getChar() method of 
Class in Java
Class in Java      ... structure. First of all learn:  what is a class in java and then move on to its...: In the java source file you generally use the package statement at header
Use of hasArray() method of ByteBuffer class in java.
Use of hasArray() method of byte buffer class in java. In this tutorial, we... or not, and provides read/write access. ByteBuffer API. The java.nio.ByteBuffer class extends java.nio.Buffer class. It provides the following methods
Use of getFloat() method of ByteBuffer class in java.
Use of getFloat() method of ByteBuffer class in java.  In this tutorial...: The java.nio.ByteBuffer class extends java.nio.Buffer class. It provides...());   } } Output C:\>java GetFloatValue

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.