DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    C. Turner Guest

    More errors in different program!


    Here is the source code. I have marked as comments where the errors
    are:
    package Timeandahalf;

    import javax.swing.JOptionPane;
    import java.lang.String;

    public class Timeandahalf {
    public static void main( String args[] ) {

    double total_wage;
    int employee, hours, hourly;
    String employee_number, hours_worked, hourly_rate;

    for (int i=0; i<7; i++) {
    employee_number = JOptionPane.showInputDialog(null,
    "Enter employee number: ");
    employee = Integer.parseInt( employee_number );

    hours_worked = JOptionPane.showInputDialog(null,
    "Enter hours worked for the week: ");
    hours = Integer.parseInt( hours_worked );

    hourly_rate = JOptionPane.showInputDialog(null,
    "Enter hourly rate: ");
    hourly = Integer.parseInt( hourly_rate );

    total_wage = hours * hourly;
    } // end of for (int i=0; i<7; i++)

    if (hours > 40) { // variable hours might not have been initialized
    total_wage = (hours * hourly) * 1.5; // variable hourly_rate
    might not have been initialized
    } // end of if hours_worked < 40

    System.out.print("Employee number: ");
    System.out.print(employee_number); // variable employee_number might
    not have been initialized
    System.out.print("Gross pay: ");
    System.out.print(total_wage); // variable total_wage might not have
    been initialized
    System.exit( 0 );
    }
    }

  2. #2
    Paul Clapham Guest

    Re: More errors in different program!

    So initialize them already. Set them to zero before the for-loop starts or
    something like that.

    PC2

    "C. Turner" <cturner@free2air.com.au> wrote in message
    news:3bfb45f7@147.208.176.211...
    >
    > Here is the source code. I have marked as comments where the errors
    > are:
    > package Timeandahalf;
    >
    > import javax.swing.JOptionPane;
    > import java.lang.String;
    >
    > public class Timeandahalf {
    > public static void main( String args[] ) {
    >
    > double total_wage;
    > int employee, hours, hourly;
    > String employee_number, hours_worked, hourly_rate;
    >
    > for (int i=0; i<7; i++) {
    > employee_number = JOptionPane.showInputDialog(null,
    > "Enter employee number: ");
    > employee = Integer.parseInt( employee_number );
    >
    > hours_worked = JOptionPane.showInputDialog(null,
    > "Enter hours worked for the week: ");
    > hours = Integer.parseInt( hours_worked );
    >
    > hourly_rate = JOptionPane.showInputDialog(null,
    > "Enter hourly rate: ");
    > hourly = Integer.parseInt( hourly_rate );
    >
    > total_wage = hours * hourly;
    > } // end of for (int i=0; i<7; i++)
    >
    > if (hours > 40) { // variable hours might not have been

    initialized
    > total_wage = (hours * hourly) * 1.5; // variable

    hourly_rate
    > might not have been initialized
    > } // end of if hours_worked < 40
    >
    > System.out.print("Employee number: ");
    > System.out.print(employee_number); // variable employee_number

    might
    > not have been initialized
    > System.out.print("Gross pay: ");
    > System.out.print(total_wage); // variable total_wage might not

    have
    > been initialized
    > System.exit( 0 );
    > }
    > }




  3. #3
    C. Turner Guest

    Re: More errors in different program!


    I have initialized hours, hourly_rate and total_wage but as employee_number
    is a String I get a different error when it is initialized. The error is
    incompatiable types: found int, required java.lang.String.
    "Paul Clapham" <pclapham@core-mark.com> wrote:
    >So initialize them already. Set them to zero before the for-loop starts

    or
    >something like that.
    >
    >PC2
    >
    >"C. Turner" <cturner@free2air.com.au> wrote in message
    >news:3bfb45f7@147.208.176.211...
    >>
    >> Here is the source code. I have marked as comments where the errors
    >> are:
    >> package Timeandahalf;
    >>
    >> import javax.swing.JOptionPane;
    >> import java.lang.String;
    >>
    >> public class Timeandahalf {
    >> public static void main( String args[] ) {
    >>
    >> double total_wage;
    >> int employee, hours, hourly;
    >> String employee_number, hours_worked, hourly_rate;
    >>
    >> for (int i=0; i<7; i++) {
    >> employee_number = JOptionPane.showInputDialog(null,
    >> "Enter employee number: ");
    >> employee = Integer.parseInt( employee_number );
    >>
    >> hours_worked = JOptionPane.showInputDialog(null,
    >> "Enter hours worked for the week: ");
    >> hours = Integer.parseInt( hours_worked );
    >>
    >> hourly_rate = JOptionPane.showInputDialog(null,
    >> "Enter hourly rate: ");
    >> hourly = Integer.parseInt( hourly_rate );
    >>
    >> total_wage = hours * hourly;
    >> } // end of for (int i=0; i<7; i++)
    >>
    >> if (hours > 40) { // variable hours might not have been

    >initialized
    >> total_wage = (hours * hourly) * 1.5; // variable

    >hourly
    >> might not have been initialized
    >> } // end of if hours_worked < 40
    >>
    >> System.out.print("Employee number: ");
    >> System.out.print(employee_number); // variable employee_number

    >might
    >> not have been initialized
    >> System.out.print("Gross pay: ");
    >> System.out.print(total_wage); // variable total_wage might not

    >have
    >> been initialized
    >> System.exit( 0 );
    >> }
    >> }

    >
    >



  4. #4
    MarkN Guest

    Re: More errors in different program!


    So convert it to a String already. (Sorry for stealing your line Paul)



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links