Thursday 4 July 2013

JOptionPane Java Program

JOptionPane Java Program


Java Code:


import java.util.Scanner;

import javax.swing.*;


public class calculate {

       /**
        * @param args
        */
       public static void main(String[] args) {
              // TODO Auto-generated method stub
               //Scanner input = new Scanner(System.in);
               
               //System.out.print("Enter the Food amount: ");
                 // float FA = input.nextFloat();
              // System.out.print("Enter the gratuity rate in percent: ");
                 // float GR = input.nextFloat();
             
              float FA = Float.parseFloat(JOptionPane.showInputDialog(null, "Enter the Food amount: "));
              float GR = Float.parseFloat(JOptionPane.showInputDialog(null, "Enter the gratuity rate in percent: "));
             
                          
                  float a=(GR*FA)/100;
                  float b=FA+a;
                  String str = String.format("%.2f", a);
                  String str1 = String.format("%.2f", b);
                  String str2 = String.format("%.2f", FA);
                  JOptionPane.showMessageDialog(null, "Food amount: " + str2);
                  JOptionPane.showMessageDialog(null, "GRATUITY: "+ str);
                  JOptionPane.showMessageDialog(null, "Total Bill: " + str1);
                 
                 /* System.out.printf("Food amount: " + "%.2f", FA);
                  System.out.println();
                  System.out.printf("GRATUITY: "+"%.2f", a);
                  System.out.println();
                  System.out.printf("Total Bill: " +"%.2f", b);
*/
        }
       }

 Snapshots:




No comments:

Post a Comment