Results 1 to 2 of 2
  1. #1
    Joshidc is offline Member
    Join Date
    Jan 2014
    Location
    Iloilo, Philippines
    Posts
    5
    Rep Power
    0

    Default i'm trying to make a calculator program with if else statement...

    hi guys sorry about bothering you... i've tried youtube for help since im practically clueless how to do stuff with java...

    Java Code:
    import javax.swing.*;
    import java.util.Scanner;
    import javax.swing.JFrame;
    
    public class OrderCalc {
    	JFrame.setDefaultLookAndFeelDecorated(true);
    	JFrame aFrame = new JFrame("OrderCalc");
    	aFrame.setSize(500,250);
    	aFrame.setVisible(true);
    }
    	
    	public static void main (String[] args) {
    		Scanner Order = new Scanner(System.in);
    		double fnum,snum,tnum,qnum,pnum,wnum,rnum,answer;
    		System.out.println("Enter First Order:");
    		fnum = Order.nextDouble();
    		System.out.println("Enter Second Order:");
    		snum = Order.nextDouble();
    		System.out.println("Are there more than 2 orders?")
    		String a = input.next();
    		if(a==Yes){
    			System.out.println("Enter Third Order:");
    			tnum = Order.nextDouble();
    			System.out.println("Is This The Last Order?");
    			
    			if (a==yes){
    				answer = fnum+snum+tnum
    				System.out.println("The Total Amount Would Be:" + answer);
    			}
    			else (a==no){
    				System.out.println("Enter Fourth Order:");
    				qnum = Order.nextDouble();
    				System.out.println("Is This The Last Order?");
    				
    				if (a==yes){
    				answer = fnum+snum+tnum+qnum
    				System.out.println("The Total Amount Would Be:" + answer);
    				}
    				else (a==no){
    				System.out.println("Enter Fifth Order:");
    				pnum = Order.nextDouble();
    				System.out.println("Is This The Last Order?");
    				
    					if (a==yes){
    					answer = fnum+snum+tnum+qnum+pnum
    					System.out.println("The Total Amount Would Be:" + answer);
    					}
    					else (a==no){
    					System.out.println("Enter Sixth Order:");
    					wnum = Order.nextDouble();
    					System.out.println("Is This The Last Order?");
    						
    							if (a==yes){
    							answer = fnum+snum+tnum+qnum+wnum;
    							System.out.println("The Total Amount Would Be:" + answer);
    							}
    							else (a==no){
    							System.out.println("Enter Seventh Order:");
    							rnum = Order.nextDouble();
    							answer = fnum+snum+tnum+qnum+wnum+rnum;
    							}
    					}
    				
    				}
    			}	
    		}
    		else (a==no){
    			answer = fnum+snum;
    			System.out.println("The Total Amount Would Be:"+ answer);
    		}
        }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: i'm trying to make a calculator program with if else statement...

    Ugh. Create a String array with the words "FIRST", "SECOND", "THIRD", etc, and use a single if block printing your "Enter" statement by indexing into the array (and automatically cutting off once the last element is used).

Similar Threads

  1. Replies: 3
    Last Post: 11-19-2012, 08:12 PM
  2. Trying to make simple calculator
    By Buldogg in forum New To Java
    Replies: 1
    Last Post: 09-18-2011, 01:37 PM
  3. Problem with if statement in a calculator program
    By peterhabe in forum New To Java
    Replies: 2
    Last Post: 08-26-2011, 05:07 PM
  4. Replies: 4
    Last Post: 07-23-2011, 08:08 PM
  5. unreachable statement - Java calculator program
    By V2001Gordon in forum New To Java
    Replies: 3
    Last Post: 12-13-2008, 12:57 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •