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?
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");
}
}
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.
Re: Help with simple program...
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.
Re: Help with simple program...
And you are correct. Welp I feel stupid haha. Thank you.