Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


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


Advertisement
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
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 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 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
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
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
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... more about the switch statement in Java. The following java program tells you... Switch Statement example in Java    
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
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 - 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
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 
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
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
Use of slice method of FloatBuffer class in java.
Use of slice method of FloatBuffer class in java. In this tutorial, we will see the use of slice method of FloatBuffer class in java. FloatBuffer API: The java.nio.FloatBuffer class extends java.nio.Buffer class. It provides
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
Use of isDirect() method of intBuffer class in java.
Use of isDirect() method of intBuffer class in java. In this tutorial, we.... The java.nio.IntBuffer class extends java.nio.Buffer class. It provides the following methods... C:\>java IntIsDirect int buffer is direct. int buffer is not direct
Use of array() method of FloatBuffer class in java.
Use of array() method of FloatBuffer class in java.  In this tutorial, we...: The java.nio.FloatBuffer class extends java.nio.Buffer class. It provides... C:>java FloatArray Capacity of float buffer : 255 Size of float
Use of equals() method of LongBuffer class in java.
Use of equals() method of LongBuffer class in java.  In this tutorial, we... API: The java.nio.LongBuffer class extends java.nio.Buffer class. It provides...; } } Output C:\>jAva EqualBuffer
Use of isDirect() method of byte buffer class in java.
Use of isDirect() method of ByteBuffer class in java. In this tutorial.... The java.nio.ByteBuffer class extends java.nio.Buffer class. It provides the following methods... is the output if you run the application: C:\>java BufferIsDirect
Use of equals() method of ByteBuffer class in java.
Use of equals() method of ByteBuffer class in java.  In this tutorial, we... or not. ByteBuffer API: The java.nio.ByteBuffer class extends java.nio.Buffer class...:\w>java ByteBufferEqual Equals Not equals Not equals Download
Use of equals() method of  FloatBuffer class in java.
Use of equals() method of  FloatBuffer class in java.  ... or not. FloatBuffer API: The java.nio.FloatBuffer class extends java.nio.Buffer class. It provides the following methods: Return type Method
Use of equals() method of IntBuffer class in java.
Use of equals() method of IntBuffer class in java.  In this tutorial, we... or not. IntBuffer API: The java.nioIntBuffer class extends java.nio.Buffer class...:\l>java EqualDemo Not equal Equal Not equal Download this code
Use of getTotalIn and getTotalOut method of Inflater class in java.
Use of getTotalIn and getTotalOut method of Inflater class in java... class. The Inflater class provide support for Decompression using ZLIB library.  The Inflater class is available in java.util.zip package.The
Use of getTotalIn and getTotalOut method of Deflater class in java.
Use of getTotalIn and getTotalOut method of Deflater class in java. In this tutorial, we will discuss the use of getTotalIn() and getTotalout() method of  Deflater. The Deflater class is used to compressed data by using ZLIB
Advertisements
 

 

 

DMCA.com