* FAQ    * Search  * Register * Login 
Active topics
Unanswered topics

All times are UTC-06:00



Post new topic  Reply to topic  [ 4 posts ] 
Author Message
 Post subject: I need some Java Help
PostPosted: Sat Feb 11, 2006 10:31 am 
Offline
DBB Ace
DBB Ace

Joined: Sun Nov 21, 1999 3:01 am
Posts: 176
ICQ: 61601718
Website: http://www.bakercountyonline.com
WLM: shade@redfaction.net
Yahoo Messenger: shaderfn
AOL: ShadeRF
Location: Florida
Hey guys I am working on a program for school and I'm having some serious issues with it. Currently it is telling me I have not declared the variable 'rate' when I try to print out my results. Maybe you guys can take a look and tell me wtf I'm doing wrong. TIA for any assistance.

Code:
import javax.swing.JOptionPane;
public class Pay
{
   public static void main(String[] args)
   {
      String jobTypeString, empHoursString;
      int jobType;
      double empHours;
      double regularPay;
      double rate;
      double grossPay = 0.0;
      double overtimePay = 0.0;
      double maxHours = 50.0;
      //Request employee type and hours worked from user
      jobTypeString = JOptionPane.showInputDialog(null,
      \"Please enter the job type.\" +
      \"/nChoose type 1, 2, or 3\");
      jobType = Integer.parseInt(jobTypeString);
      empHoursString = JOptionPane.showInputDialog(null,
      \"Please enter the hours worked.\" +
      \"/nHours are not to exceed 50.\");
      empHours = Integer.parseInt(empHoursString);

         
      if(jobType == 1 && empHours <= 50 && empHours > 40)
         {
            rate = 7.00;
            regularPay = 40 * rate;
            overtimePay = (empHours - 40) * 2 * rate;
            grossPay = regularPay + overtimePay;
         }
         else if(empHours < 40)
         {
            rate = 7.00;
            regularPay = 40 * rate;
            overtimePay = overtimePay;
            grossPay = regularPay + overtimePay;
         }
      else if(jobType == 2 && empHours <= 50 && empHours > 40)
         {
            rate = 10.00;
            regularPay = 40 * rate;
            overtimePay = (empHours - 40) * 2 * rate;
            grossPay = regularPay + overtimePay;
         }
         else if(empHours < 40)
         {
            rate = 10.00;
            regularPay = 40 * rate;
            overtimePay = overtimePay;
            grossPay = regularPay + overtimePay;
         }
      else if(jobType == 3 && empHours <= 50 && empHours > 40)
         {
            rate = 12.00;
            regularPay = 40 * rate;
            overtimePay = (empHours - 40) * 2 * rate;
            grossPay = regularPay + overtimePay;
         }
         else if(empHours < 40)
         {
            rate = 12.00;
            regularPay = 40 * rate;
            overtimePay = overtimePay;
            grossPay = regularPay + overtimePay;
         }   
      //Display hours worked, rate, regular pay, and overtime pay for employee.
      JOptionPane.showMessageDialog(null,
      \"The employee worked \" + empHours + \" at the rate of \" + rate +
      \"dollars per hour.\" +
      \"/nThe regular pay amount for the week is \" + regularPay +
      \"/nThe overtime pay amount for the week is \" + overtimePay +
      \"/nThe gross pay amount for the week is \" + grossPay);
      System.exit(0);
   }
}


Top
   
 Post subject:
PostPosted: Sat Feb 11, 2006 12:08 pm 
Offline
DBB Captain
DBB Captain
User avatar

Joined: Thu Nov 05, 1998 12:01 pm
Posts: 589
ICQ: 247668
Website: http://www.descentrangers.com/
WLM: verraneventide@hotmail.com
Yahoo Messenger: verraneventide
AOL: verraneventide
Location: Colorado
Some of your member variables needed to be given a default value. I also fixed /n to \\n and made the messages a little prettier.

Code:
import javax.swing.JOptionPane;
public class Pay
{
   public static void main(String[] args)
   {
      String jobTypeString, empHoursString;
      int jobType;
      double empHours = 0.0;
      double regularPay = 0.0;
      double rate = 0.0;
      double grossPay = 0.0;
      double overtimePay = 0.0;
      double maxHours = 50.0;
      //Request employee type and hours worked from user
      jobTypeString = JOptionPane.showInputDialog(null,
      \"Please enter the job type. \" +
      \"\\nChoose type 1, 2, or 3\");
      jobType = Integer.parseInt(jobTypeString);
      empHoursString = JOptionPane.showInputDialog(null,
      \"Please enter the hours worked. \" +
      \"\\nHours are not to exceed 50.\");
      empHours = Integer.parseInt(empHoursString);

         
      if(jobType == 1 && empHours <= 50 && empHours > 40)
         {
            rate = 7.00;
            regularPay = 40 * rate;
            overtimePay = (empHours - 40) * 2 * rate;
            grossPay = regularPay + overtimePay;
         }
         else if(empHours < 40)
         {
            rate = 7.00;
            regularPay = 40 * rate;
            overtimePay = overtimePay;
            grossPay = regularPay + overtimePay;
         }
      else if(jobType == 2 && empHours <= 50 && empHours > 40)
         {
            rate = 10.00;
            regularPay = 40 * rate;
            overtimePay = (empHours - 40) * 2 * rate;
            grossPay = regularPay + overtimePay;
         }
         else if(empHours < 40)
         {
            rate = 10.00;
            regularPay = 40 * rate;
            overtimePay = overtimePay;
            grossPay = regularPay + overtimePay;
         }
      else if(jobType == 3 && empHours <= 50 && empHours > 40)
         {
            rate = 12.00;
            regularPay = 40 * rate;
            overtimePay = (empHours - 40) * 2 * rate;
            grossPay = regularPay + overtimePay;
         }
         else if(empHours < 40)
         {
            rate = 12.00;
            regularPay = 40 * rate;
            overtimePay = overtimePay;
            grossPay = regularPay + overtimePay;
         }   
      //Display hours worked, rate, regular pay, and overtime pay for employee.
      JOptionPane.showMessageDialog(null,
      \"The employee worked \" + empHours + \" at the rate of \" + rate +
      \"dollars per hour.\" +
      \"\\nThe regular pay amount for the week is \" + regularPay +
      \"\\nThe overtime pay amount for the week is \" + overtimePay +
      \"\\nThe gross pay amount for the week is \" + grossPay);
      System.exit(0);
   }
}

_________________
.
http://www.descentrangers.com

http://soundcloud.com/verran


Top
   
 Post subject:
PostPosted: Sat Feb 11, 2006 12:44 pm 
Offline
DBB Ace
DBB Ace

Joined: Sun Nov 21, 1999 3:01 am
Posts: 176
ICQ: 61601718
Website: http://www.bakercountyonline.com
WLM: shade@redfaction.net
Yahoo Messenger: shaderfn
AOL: ShadeRF
Location: Florida
Thanks for the help. However I am noticing now that when I display the results it is outputting 0.0 as the result for everything except the hours worked. What would u suggest for fixing this problem?


Top
   
 Post subject:
PostPosted: Sat Feb 11, 2006 12:59 pm 
Offline
DBB Ace
DBB Ace

Joined: Sun Nov 21, 1999 3:01 am
Posts: 176
ICQ: 61601718
Website: http://www.bakercountyonline.com
WLM: shade@redfaction.net
Yahoo Messenger: shaderfn
AOL: ShadeRF
Location: Florida
Nevermind. I fixed it! Thanks a ton :)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Descent'rs have piloted these pages
 
The layout and contents contained within this site are © DescentBB.net 1997-2006.
Descent, Descent II are © Parallax Software Corporation.
Descent III is Outrage Entertainment.
Descent is a Trademark of Interplay Productions.

Miner Wars™ is trademark of Keen Software House s. r. o.
.


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group