Results 1 to 5 of 5
  1. #1
    blink16j is offline Member
    Join Date
    Jan 2013
    Posts
    9
    Rep Power
    0

    Default Help with simple program...

    I know that each function will run individually but when put together Function 2 does not start (JOption Message does not popup). Do I need to insert something after the last line of Function 1 so Function 2 starts?

    Java Code:
    package lab1;
    
    /**
     *
     * @author James Doyle
     */
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    
    public class JamesDoyleLab1
    {
        public static void main(String[] args) 
        {
            //Start Function 1
            System.out.println("Lab 1 written by James Doyle");
        
            Scanner keyboard = new Scanner(System.in);
            
            System.out.print("Enter your name: ");
            String userName = keyboard.nextLine();
            System.out.print("Enter height in feet: ");
            String userHeight = keyboard.nextLine();
            
            Double dblHeight = Double.valueOf(userHeight);
            String cmHeight = Double.toString(dblHeight*30.48);
            
            System.out.println(userName + " has height in centimeters of " + cmHeight);
            
            //Start Function 2
            JOptionPane.showMessageDialog(null, "Part 2 will use a JOption Pane");
            String employeeName = JOptionPane.showInputDialog("Enter employee name");
            
            String hoursWorkedStr = JOptionPane.showInputDialog("Enter hours worked");
            //Convert string to double
            Double hoursWorked = Double.parseDouble(hoursWorkedStr);
            
            String payRateStr = JOptionPane.showInputDialog("Enter hourly pay rate");
            //Convert string to double
            Double payRate = Double.parseDouble(payRateStr);
              
            String percentageStr = JOptionPane.showInputDialog("Enter expense as a percentage (10% should be entered as 10)");
            //Convert string to double
            Double percentage = Double.parseDouble(percentageStr);
            
            Double totalAmt = hoursWorked*payRate*((100-percentage)/100);
            
            //Display results
            String output = "Written by James Doyle" +
                            "\nName: " + employeeName +
                            "\nHours Worked: " + hoursWorkedStr +
                            "\nHourly Pay Rate: $" + payRateStr +
                            "\nExpense Percent " + percentageStr +
                            "\nTotal Amount after Expenses: $" + totalAmt;
            JOptionPane.showMessageDialog(null, output);
            JOptionPane.showMessageDialog(null, "James Doyle Lab1 has ended");
            
        }
    }
    Last edited by blink16j; 01-15-2013 at 06:11 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,558
    Rep Power
    25

    Default Re: Help with simple program...

    Please edit the post and wrap the code in code tags. See BB Code List - Java Programming Forum - Learn Java Programming
    Unformated code is hard to read and understand.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    blink16j is offline Member
    Join Date
    Jan 2013
    Posts
    9
    Rep Power
    0

    Default Re: Help with simple program...

    Sorry about that.

  4. #4
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Help with simple program...

    Make sure your dialog does not open hidden behind your IDE window... the program should work fine. Minimize your IDE after entering the two first lines.
    I like likes!

  5. #5
    blink16j is offline Member
    Join Date
    Jan 2013
    Posts
    9
    Rep Power
    0

    Default Re: Help with simple program...

    And you are correct. Welp I feel stupid haha. Thank you.

Similar Threads

  1. Help with a simple tax program
    By Shea6892 in forum New To Java
    Replies: 3
    Last Post: 02-03-2012, 05:35 PM
  2. Simple program, simple problem
    By taymilll in forum New To Java
    Replies: 12
    Last Post: 06-20-2011, 05:12 AM
  3. simple program
    By kayln in forum Eclipse
    Replies: 0
    Last Post: 05-01-2011, 10:03 PM
  4. Please help with simple program.. Very simple.
    By jonytek in forum New To Java
    Replies: 7
    Last Post: 02-14-2011, 12:44 AM
  5. Simple Program
    By TheRocket in forum Advanced Java
    Replies: 15
    Last Post: 12-30-2008, 02:35 PM

Posting Permissions

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