I am trying to edit a code we were given and it's not working for me when I incorporate the scanner code

Basically every place where the code says 'public static void', it says there is an illegal start of expression

I HAVE to use methods for this code I know there's an easier way but I can't do it that way and a lot of the times it says it can't read the reader.nextDouble

import java.util.Scanner;

public class Share {
private static double hourlyWage;
           private static double regularHours;
           private static double overtimeHours;
           private static double regularPay;
           private static double overtimePay;
           private static double total;
public static void main(String Args[])
{
Scanner reader = new Scanner(System.in);





{
  //method call statements

     setHourlyWage();
     setRegHours();
     setOvertimeHours();
     calcRegPay();
     calcOvertimePay();
     calcTotal();
     printResults();
 }


 public static void setHourlyWage()   
 {
 
       System.out.print("Enter Hourly Wage: ");
  hourlyWage = reader.nextDouble();
  }



 public static void setRegHours()  header lines
 {
 System.out.print("Enter Regular Hours: ");
  regularHours = reader.nextDouble();
 }


  public static void setOvertimeHours()
 {
       System.out.print("Enter Overtime Hours: ");
  overtimeHours = reader.nextDouble();
 }

public static void calcRegPay()
{
regularPay = hourlyWage * regularHours;
}

public static void calcOvertimePay();
{
overtimePay = overtimeHours * 1.5 * hourlyWage;
}

public static void calcTotal();
{
total = hourlyWage * regularHours + (overtimeHours * 1.5 * hourlyWage);
}

public static void printResults();
{
System.out.print("The total regular pay is ");
  System.out.println(regularPay);

System.out.print("The total overtime pay is ");
  System.out.println(overtimePay);

System.out.print("The total weekly wage is ");
  System.out.println(total);
}
}

I fixed it to this and instead of having 53 errors, I now only have three saying 'non static variable reader cannot be referenced from static context' on lines 47, 56, and 64

import java.util.Scanner;

public class Blah {

public static void main(String Args[])
{
}
private static double hourlyWage;
{
}
private static double regularHours;
{
}
private static double overtimeHours;
{
}
private static double regularPay;
{
}
private static double overtimePay;
{
}
private static double total;
{
}
Scanner reader = new Scanner(System.in);



{

     setHourlyWage();
     setRegHours();
     setOvertimeHours();
     calcRegPay();
     calcOvertimePay();
     calcTotal();
     printResults();
 }



 public static void setHourlyWage()  
 {
 
       System.out.print("Enter Hourly Wage: ");
  hourlyWage = reader.nextDouble();
  }




 public static void setRegHours() 
 {
 System.out.print("Enter Regular Hours: ");
  regularHours = reader.nextDouble();
 }


 // output results
  public static void setOvertimeHours()
 {
       System.out.print("Enter Overtime Hours: ");
  overtimeHours = reader.nextDouble();
 }

public static void calcRegPay()
{
regularPay = hourlyWage * regularHours;
}

public static void calcOvertimePay()
{
overtimePay = overtimeHours * 1.5 * hourlyWage;
}

public static void calcTotal()
{
total = hourlyWage * regularHours + (overtimeHours * 1.5 * hourlyWage);
}

public static void printResults()
{
System.out.print("The total regular pay is ");
  System.out.println(regularPay);

System.out.print("The total overtime pay is ");
  System.out.println(overtimePay);

System.out.print("The total weekly wage is ");
  System.out.println(total);
}
}

 // end of Share class

You still have problems with your method blocks and braces. The only problem with your first version was that you tried to declare the methods inside the main() method rather than outside of it. You can't declare methods within methods.

The second version has no code at all in main() and many other empty blocks (between braces). You need to fix all of those brace problems so your class is structured properly. example

public class Blah {
  public static double hourlyWage;

  public static void main(String Args[])
  {
    setHourlyWage();
  }

  public static void setHourlyWage()  
  {
   ...
  }

}

Look more closely at the structure of the methods and note that the braces denote the beginning and ending of the method bodies.

Thanks I'll try it that way right now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.