Results 1 to 5 of 5
Thread: Help with simple program...
- 01-15-2013, 03:20 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 8
- Rep Power
- 0
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.
- 01-15-2013, 03:42 AM #2
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.
- 01-15-2013, 06:12 AM #3
Member
- Join Date
- Jan 2013
- Posts
- 8
- Rep Power
- 0
Re: Help with simple program...
Sorry about that.
- 01-15-2013, 09:40 AM #4
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
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!.gif)
- 01-15-2013, 05:59 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Help with a simple tax program
By Shea6892 in forum New To JavaReplies: 3Last Post: 02-03-2012, 05:35 PM -
Simple program, simple problem
By taymilll in forum New To JavaReplies: 12Last Post: 06-20-2011, 05:12 AM -
simple program
By kayln in forum EclipseReplies: 0Last Post: 05-01-2011, 10:03 PM -
Please help with simple program.. Very simple.
By jonytek in forum New To JavaReplies: 7Last Post: 02-14-2011, 12:44 AM -
Simple Program
By TheRocket in forum Advanced JavaReplies: 15Last Post: 12-30-2008, 02:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks