There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Java Help


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
fyrejumper's Avatar
Computer Specs
Junior Member with 4 posts.
 
Join Date: Nov 2007
Experience: Beginner
02-Nov-2007, 12:33 AM #1
Java Help
Hi!! I'm new to Java and am trying to learn it as best I can. I keep getting an error message: WeeklyPay.java:58: illegal start of expression
static Scanner sc = new Scanner(System.in);
^
1 error

I can't figure out where I've messed up. The program is intended to output the weekly pay and then ask the user to enter another name Yes or No and either continue or quit based on user input. Can anyone please assist with this? I have listed the program below.

Thanks in advance!!

/**
* @(#)WeeklyPay.java
*
*
* @
* @version 1.00 2007/10/23
*/

import java.util.Scanner; // program uses Scanner

import java.io.*; // program uses input/output


public class WeeklyPay

{
public static void main( String[] args )

{
// prompt the user to enter employee name
System.out.print("Please enter employee last name, first name: ");

// open standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String employeeName = null;

// read username from command-line; use try/catch with the readline() method

try
{
employeeName = br.readLine();
}

catch (IOException ioe)
{
System.out.println("IO error trying to read employee name!");
System.exit(1);
}

// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );

int x; // employee hourly wage
int y; // employee hours work for week
int result; // total weekly pay

System.out.print( "Enter employees hourly wage: " ); // prompt for hourly wage
x = input.nextInt(); // read hourly wage

System.out.print( "Enter employee hours worked for the week: " ); // prompt for hours worked for week
y = input.nextInt(); // read employee hours

result = x * y; //calculate weekly pay

System.out.printf( "Weekly Pay is $%d\n", result ); //output weekly pay

static Scanner sc = new Scanner(System.in);

{
String input = "Y";
while (input.equals("Y"))
{
System.out.println(" ");
System.out.print
("Do you want to enter another employee name?" + " (Y or N)");
input = sc.next();
}
}

} // end method main

} //end class WeeklyPay
Chicon's Avatar
Computer Specs
Distinguished Member with 6,598 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
02-Nov-2007, 02:18 AM #2
Hi fyrejumper,

Welcome to TSG !

- the static modifier is wrong :
line : static Scanner sc = new Scanner(System.in);

- The assignment String input = "Y"; is wrong because the line :
Scanner input = new Scanner( System.in );
fyrejumper's Avatar
Computer Specs
Junior Member with 4 posts.
 
Join Date: Nov 2007
Experience: Beginner
02-Nov-2007, 09:01 AM #3
Quote:
Originally Posted by Chicon
Hi fyrejumper,

Welcome to TSG !

- the static modifier is wrong :
line : static Scanner sc = new Scanner(System.in);

- The assignment String input = "Y"; is wrong because the line :
Scanner input = new Scanner( System.in );

Thanks for the welcome Chicon. I am still lost on the concept. Remember I am a newbie. What do you mean by the static modifier and the assignmnet is wrong?

Thanks!!
Chicon's Avatar
Computer Specs
Distinguished Member with 6,598 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
02-Nov-2007, 10:45 AM #4
In Java, modifiers are terms like public, private, final, abstract and so on ... On this page, you'll find a short summary of Java modifiers and their meaning.
static variables or fields must be declared outside methods.

Assignements are not specific to Java language.
Expressions like :
String input = "Y"; in Java
Let A = 15 in Basic
MOVE 10 TO VARIABLE in Cobol
...
are called assignments; they mean : assign the value something to the variable some_name.
In your program, you're declaring the same name input for 2 different things : Scanner and String.
fyrejumper's Avatar
Computer Specs
Junior Member with 4 posts.
 
Join Date: Nov 2007
Experience: Beginner
06-Nov-2007, 10:31 PM #5
Quote:
Originally Posted by Chicon
In Java, modifiers are terms like public, private, final, abstract and so on ... On this page, you'll find a short summary of Java modifiers and their meaning.
static variables or fields must be declared outside methods.

Assignements are not specific to Java language.
Expressions like :
String input = "Y"; in Java
Let A = 15 in Basic
MOVE 10 TO VARIABLE in Cobol
...
are called assignments; they mean : assign the value something to the variable some_name.
In your program, you're declaring the same name input for 2 different things : Scanner and String.
Chicon,

I see what your talking about now, I just don't understand how to fix it.

Thanks
Chicon's Avatar
Computer Specs
Distinguished Member with 6,598 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
07-Nov-2007, 06:43 AM #6
Just replace the second declaration of input by another name, response for example :

Code:

String response = "Y";
while (response.equals("Y"))
{
    System.out.println(" ");
    System.out.print("Do you want to enter another employee name?" + " (Y or N)");
    response = sc.next();
}
fyrejumper's Avatar
Computer Specs
Junior Member with 4 posts.
 
Join Date: Nov 2007
Experience: Beginner
07-Nov-2007, 08:28 AM #7
Quote:
Originally Posted by Chicon
Just replace the second declaration of input by another name, response for example :

Code:

String response = "Y";
while (response.equals("Y"))
{
    System.out.println(" ");
    System.out.print("Do you want to enter another employee name?" + " (Y or N)");
    response = sc.next();
}
Something so simple. I think I'm getting an idea now. Thanks!!!
Chicon's Avatar
Computer Specs
Distinguished Member with 6,598 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
07-Nov-2007, 11:10 AM #8
You're welcome !
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:59 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.