Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #2258 > unrolled thread

final error and i cant figure this out.OMG

Started bytyrelmatadin921@gmail.com
First post2012-11-14 17:59 -0800
Last post2012-11-17 10:46 -0800
Articles 4 — 4 participants

Back to article view | Back to comp.lang.java.help


Contents

  final error and i cant figure this out.OMG tyrelmatadin921@gmail.com - 2012-11-14 17:59 -0800
    Re: final error and i cant figure this out.OMG "John B. Matthews" <nospam@nospam.invalid> - 2012-11-14 21:51 -0500
    Re: final error and i cant figure this out.OMG Lew <lewbloch@gmail.com> - 2012-11-15 12:55 -0800
    Re: final error and i cant figure this out.OMG Roedy Green <see_website@mindprod.com.invalid> - 2012-11-17 10:46 -0800

#2258 — final error and i cant figure this out.OMG

Fromtyrelmatadin921@gmail.com
Date2012-11-14 17:59 -0800
Subjectfinal error and i cant figure this out.OMG
Message-ID<1e645df1-19c8-42ed-8034-1c11fe7771ba@googlegroups.com>
Im almost finished and this code is giving me an error.i have been trying to fix it for 6 hours now. can someone please help me. the comiler error keeps saying, " identifer expected, illigel start of type. this is my code:

package sheridan;

import java.util.Scanner;

public class PayrollApplication
{
    
    
    public static void main (String[] args)
    {
        
        
        
        PayrollApplication app = new PayrollApplication();
        app.run(); 
        
        
       
        
        
        
        
        
    }
    
    private void run()
    {
        
        
        
        Employee employeeInfo = new Employee();
        
        System.out.println ("Enter employee's name:");
        Scanner input = new Scanner(System.in);
        String employeeName = input.nextLine();
        
        if (employeeName.length()==0)
        {
            System.out.println("Not Entered"); 
        }
        
        System.out.println("Enter number of hours worked in a week:");
        double weeklyHoursFromUser = input.nextDouble();
        employeeInfo.setWeeklyHours(weeklyHoursFromUser);
        
        
        if (weeklyHoursFromUser <= 0)
        {
            System.out.println("You have entered an incorrect number of hours");
            return;
        }
        
        
        
        System.out.println("Enter your hourly pay rate");
        double hourlyPayRateFromUser = input.nextDouble();
        employeeInfo.setHourlyPayRate(hourlyPayRateFromUser);
        
        if (hourlyPayRateFromUser <= 0)
        {
            System.out.println(" you have entered an incorrect pay rate ");
            return;
        }

        System.out.println("Enter Federal tax withholding rate");
        double federalTaxRateFromUser = input.nextDouble();
        employeeInfo.setFederalTaxRate(federalTaxRateFromUser);
        
        if (federalTaxRateFromUser <=0 || federalTaxRateFromUser>=1)
        {
            System.out.println(" You have entered an incorrect amount for the Federal tax. Please run the program again and enter a real number between 0 and 1 exclusively.");
            return;
        }
        
        
        System.out.println("Enter State tax withholding rate");
        double stateTaxRateFromUser = input.nextDouble();
        employeeInfo.setStateTaxRate(stateTaxRateFromUser);
        
        if (stateTaxRateFromUser <=0 || stateTaxRateFromUser>=1)
        {
            System.out.println("You have entered an incorrect amount for the State tax. Please run the program again and enter a real number between 0 and 1 exclusively.");
            return;

        }
       calculateUserPay();
        
        
    }
        
        
      private double calculateUserPay() 
          
    { 
        Employee employeeInfo = new Employee();
        double weeklyHours = employeeInfo.getWeeklyHours();
        double payRate =  employeeInfo.getHourlyPayRate();
        double federalTax = employeeInfo.getFederalTaxRate();
        double stateTax = employeeInfo.getStateTaxRate();
        
        if(weeklyHours<40)
        {
            double netPay =  payRate * weeklyHours - federalTax + stateTax;
            return netPay;
        }
        else
        {
        double overTime = 40 * payRate + (weeklyHours - 40)*(payRate * 1.5) - federalTax + stateTax;
        
        printStatement();
        } 
    } 

    
    
    
    
   private void printStatement()
    {
      
            
            System.out.println ("Employee Name:"+ employeeName);
            System.out.println ("Hours worked:" + weeklyHoursFromUser );
            System.out.println ("Pay rate:"+ hourlyPayRateFromUser);
            System.out.println ("Gross pay:"+ hourlyPayRateFromUser * weeklyHoursFromUser );
            System.out.println ("Deductions" );
            System.out.println ("Federal Withholding" + federalTaxRateFromUser*(hourlyPayRateFromUser * weeklyHoursFromUser));
            System.out.println ("State Withholding" + stateTaxRateFromUser * (hourlyPayRateFromUser * weeklyHoursFromUser));
            System.out.println ("Total deduction:" + weeklyHoursFromUser * hourlyPayRateFromUser-( federalTaxRateFromUser*(hourlyPayRateFromUser * weeklyHoursFromUser))-(stateTaxRateFromUser * (hourlyPayRateFromUser * weeklyHoursFromUser)));
            System.out.println ("Net Pay:" );
   }






and my Employee class is:





package sheridan;

import java.util.Scanner;

public class Employee
{
   
    Employee employeeInfo = new Employee();
    
    private double _weeklyHours;
    
    private double _hourlyPayRate;
    
    private double _federalTaxRate;
    
    private double _stateTaxRate;
    
   
    
   
   
    
   
    public double getWeeklyHours()
    {
        return _weeklyHours;
    }
    public void setWeeklyHours (double newWeeklyHoursParam)
    {
        _weeklyHours = newWeeklyHoursParam;
    }
    public double getHourlyPayRate()
    {
        return _hourlyPayRate;
    }
    public void setHourlyPayRate (double newHourlyPayRateParam)
    {
        _hourlyPayRate = newHourlyPayRateParam;
    }
    public double getFederalTaxRate()
    {
        return _federalTaxRate;
    }
    public void setFederalTaxRate (double newFederalTaxRateParam)
    {
        _federalTaxRate = newFederalTaxRateParam;
    }
    public double getStateTaxRate()
    {
        return _stateTaxRate;
    }
    public void setStateTaxRate (double newStateTaxRateParam)
    {
        _stateTaxRate = newStateTaxRateParam;
    }     
    
}

     

        

[toc] | [next] | [standalone]


#2259

From"John B. Matthews" <nospam@nospam.invalid>
Date2012-11-14 21:51 -0500
Message-ID<nospam-625B44.21514614112012@news.aioe.org>
In reply to#2258
In article <1e645df1-19c8-42ed-8034-1c11fe7771ba@googlegroups.com>,
 tyrelmatadin921@gmail.com wrote:

> I'm almost finished, and this code is giving me an error. I have been 
> trying to fix it for 6 hours, now. Can someone please help me? The 
> compiler error keeps saying, "identifer expected, illegal start of 
> type." This is my code:

The biggest problem that I encountered is excerpted below. The 
initialization of employeeInfo recursively invokes the Employee 
constructor until memory is exhausted and execution ends with a 
java.lang.StackOverflowError.

public class Employee
{
    Employee employeeInfo = new Employee();
    ...
}

You might want to look at "Providing Constructors for Your Classes:"

<http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

[toc] | [prev] | [next] | [standalone]


#2268

FromLew <lewbloch@gmail.com>
Date2012-11-15 12:55 -0800
Message-ID<84624f0f-2ae8-4a62-a840-510639f9f6b7@googlegroups.com>
In reply to#2258
tyrelma...@ wrote:
> Im almost finished and this code is giving me an error.i [sic] have been trying to fix it for 6 hours 
> now. can someone please help me. the comiler error keeps saying, " identifer expected, illigel start of 
> type. this is my code:

In future, COPY and PASTE error messages. For one thing, that will avoid misspellings, but more 
importantly it will provide more information for those inclined to help you.

Such as, for example, what line of code triggered the error, and what position in that line.
Why would you omit that vital information anyway?

> package sheridan;
> 
> import java.util.Scanner;
> 
> public class PayrollApplication
> {
> 
>     public static void main (String[] args)
>     {
>         PayrollApplication app = new PayrollApplication();
>         app.run(); 
>     }
> 
>     private void run()

If you name a no-arg, void-returning method 'run()', you should consider making 
it public. It's the traditional name for a public go-ahead method such as 'Runnable' 
sports.

>     {
>         Employee employeeInfo = new Employee();
>         System.out.println ("Enter employee's name:");
>         Scanner input = new Scanner(System.in);
>         String employeeName = input.nextLine();

>         if (employeeName.length()==0)
>         {
>             System.out.println("Not Entered"); 
>         }         
> 
>         System.out.println("Enter number of hours worked in a week:");
>         double weeklyHoursFromUser = input.nextDouble();
>         employeeInfo.setWeeklyHours(weeklyHoursFromUser);
> 
>         if (weeklyHoursFromUser <= 0)
>         {
>             System.out.println("You have entered an incorrect number of hours");
>             return;
>         }
> 
>         System.out.println("Enter your hourly pay rate");
>         double hourlyPayRateFromUser = input.nextDouble();
>         employeeInfo.setHourlyPayRate(hourlyPayRateFromUser);
> 
>         if (hourlyPayRateFromUser <= 0)
>         {
>             System.out.println(" you have entered an incorrect pay rate ");
>             return;
>         }
> 
>         System.out.println("Enter Federal tax withholding rate");
>         double federalTaxRateFromUser = input.nextDouble();
>         employeeInfo.setFederalTaxRate(federalTaxRateFromUser);
> 
>         if (federalTaxRateFromUser <=0 || federalTaxRateFromUser>=1)
>         {
>             System.out.println(" You have entered an incorrect amount for the Federal tax. Please run the program again and enter a real number between 0 and 1 exclusively.");

"... between 0 and 1, exclusive."

"Exclusively" doesn't mean what you mean to mean.

>             return;
>         }
> 
>         System.out.println("Enter State tax withholding rate");
>         double stateTaxRateFromUser = input.nextDouble();
>         employeeInfo.setStateTaxRate(stateTaxRateFromUser);
> 
>         if (stateTaxRateFromUser <=0 || stateTaxRateFromUser>=1)
>         {
>             System.out.println("You have entered an incorrect amount for the State tax. Please run the program again and enter a real number between 0 and 1 exclusively.");
>             return;
>         }
> 
>        calculateUserPay();
>     }
> 
>       private double calculateUserPay() 
>     { 
>         Employee employeeInfo = new Employee();
>         double weeklyHours = employeeInfo.getWeeklyHours();
>         double payRate =  employeeInfo.getHourlyPayRate();
>         double federalTax = employeeInfo.getFederalTaxRate();
>         double stateTax = employeeInfo.getStateTaxRate();
> 
>         if(weeklyHours<40)
>         {
>             double netPay =  payRate * weeklyHours - federalTax + stateTax;
>             return netPay;
>         }
>         else
>         {
>         double overTime = 40 * payRate + (weeklyHours - 40)*(payRate * 1.5) - federalTax + stateTax;
>         printStatement();
>         } 
>     } 
> 
>    private void printStatement()
>     {
>             System.out.println ("Employee Name:"+ employeeName);

And just where is 'employeeName' declared?

>             System.out.println ("Hours worked:" + weeklyHoursFromUser );

Ditto 'weeklyHoursFromUse'. 

>             System.out.println ("Pay rate:"+ hourlyPayRateFromUser);

etc.

>             System.out.println ("Gross pay:"+ hourlyPayRateFromUser * weeklyHoursFromUser );
>             System.out.println ("Deductions" );
>             System.out.println ("Federal Withholding" + federalTaxRateFromUser*(hourlyPayRateFromUser * weeklyHoursFromUser));
>             System.out.println ("State Withholding" + stateTaxRateFromUser * (hourlyPayRateFromUser * weeklyHoursFromUser));
>             System.out.println ("Total deduction:" + weeklyHoursFromUser * hourlyPayRateFromUser-( federalTaxRateFromUser*(hourlyPayRateFromUser * weeklyHoursFromUser))-(stateTaxRateFromUser * (hourlyPayRateFromUser * weeklyHoursFromUser)));
> 
>             System.out.println ("Net Pay:" );
>    }

Variables have to be declared before you can use them.
> 
> and my Employee class is:
> 
> package sheridan;
> 
> import java.util.Scanner;
> 
> public class Employee
> {
>     Employee employeeInfo = new Employee();

BRAAAAAHHHHH!

How can you instantiate an 'Employee' inside an 'Employee''s instantiation, as 
John B. Matthews pointed out?

>     private double _weeklyHours;

Don't use underscores in variable names unless they're constant variables (or at 
least final references to immutable instances).

>     private double _hourlyPayRate;
>     private double _federalTaxRate;
>     private double _stateTaxRate;
> 
>     public double getWeeklyHours()
>     {
>         return _weeklyHours;
>     }
> 
>     public void setWeeklyHours (double newWeeklyHoursParam)
>     {
>         _weeklyHours = newWeeklyHoursParam;
>     }
> 
>     public double getHourlyPayRate()
>     {
>         return _hourlyPayRate;
>     }
> 
>     public void setHourlyPayRate (double newHourlyPayRateParam)
>     {
>         _hourlyPayRate = newHourlyPayRateParam;
>     }
> 
>     public double getFederalTaxRate()
>     {
>         return _federalTaxRate;
>     }
> 
>     public void setFederalTaxRate (double newFederalTaxRateParam)
>     {
>         _federalTaxRate = newFederalTaxRateParam;
>     }
> 
>     public double getStateTaxRate()
>     {
>         return _stateTaxRate;
>     }
> 
>     public void setStateTaxRate (double newStateTaxRateParam)
>     {
>         _stateTaxRate = newStateTaxRateParam;
>     }     
> 
> }

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#2280

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-11-17 10:46 -0800
Message-ID<qmmfa85o78k4daqikhk16teupbu2njs0vo@4ax.com>
In reply to#2258
On Wed, 14 Nov 2012 17:59:19 -0800 (PST), tyrelmatadin921@gmail.com
wrote, quoted or indirectly quoted someone who said :

>dentifer expected, illigel start of type.

go see http://mindprod.com/jgloss/compileerrormessages.html
whenever you can't understand what a compile time error message means.

Also see http://mindprod.com/jgloss/sscce.html

Remember to show WHERE in your program it is complaining.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Types of Garbage Collection:
()In Canada, the government sends men to your house every every week
  to take away your garbage. Hoarders are free to hang onto things 
  they don't really need.
()In third world countries, it is up to you to take your own garbage away.
()Java's garbage collection system is analogous to a garbage removal
  system where every hour, workers scan your house for junk mail, the
  contents of waste baskets, carpet lint, toenail clippings and anything 
  else they are absolutely sure you don't want to keep.
()C++'s system for disposing of unreferenced objects is similar to India's,
  with the strange feature that undiscarded garbage becomes invisible but
  still stinks.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.help


csiph-web