Aretha Clark

Greenhorn
+ Follow
since Mar 07, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Aretha Clark

Im looking for some guidance as to how i would go about moving implemenation out of main(String[ ] args). I have tried to do this a few times and all i seem to do is mess up my code.

15 years ago
Im using txtpad so i not sure

Have you got a text editor which supports syntax highlighting?



However i have managed to get less errors . Im just not sure if im making progress or moving backwards

15 years ago
The error i recieved was ..

Payroll.java:92: reached end of file while parsing




[GDB - Editing to use UBB Code Tags ]
[ June 24, 2008: Message edited by: Gregg Bolinger ]
15 years ago
In the midst of writing the code for my java program, i have seem to taken a misturn somewhere. Any advise or sugestions on what i can do to correct this is much needed. It works good until i get to the employee class near the bottom.

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

public class Payroll {

public Payroll() {

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

String employeeName = ""; //input employee name
double hourlyWage;
double hoursWorked;
double weeklyPay;

// loop until the user enters 'stop' as the name of the employee.
do {

// Get Employee Name
System.out.print("Enter Name of Employee:");
employeeName = input.next();
// if the employee name is 'stop', then exit the loop.
if (employeeName.equals("stop")) {
break;

}

// ask for hourly wage
System.out.print("Enter hourly Wage:");
hourlyWage = input.nextDouble();
// require that the hourly wage is a non-negative
while (hourlyWage < 0.0)
{
System.out.print("Hourly wage must be a positive number. Please enter a positive hourly wage:");//prompt
hourlyWage = input.nextDouble();
input.nextLine();

}

// ask the hours worked
System.out.print("Enter hours worked:");
hoursWorked = input.nextDouble();
// require that hours worked be a non-negative number
while (hoursWorked < 0.0)
{
System.out.print("Hours worked must be a positive number. Please enter a positive number of hours:");//prompt
hoursWorked=input.nextDouble();

input.nextLine();
}


weeklyPay = hourlyWage * hoursWorked;
System.out.printf("The employee, %s, was paid $ %.2f this week.\n\n", employeeName, weeklyPay);

} while (true);


}
} public static void main(String args[]) {
new Payroll();

} //end method main

//end class Payroll



public class Employee {

public Employee() {

String name;
int hoursworked;
int hourlywage;
int weeklyPay;

public Employee(String name, int hours, int rate) {
this.name = name;
this.hoursworked = hours;
hourlywage = rate;
computeWeeklyPay();
}

private void computeWeeklyPay() {
weeklyPay = hoursworked * hourlywage;
}

public int getWeeklyPay() {
return weeklyPay;
}
;
15 years ago
anyone know where i can find some very basic examples of how to add a second method to existing code
15 years ago
Thank you very much its almost sickening that the misplacement of brackets can turn into a nightmare
15 years ago
Thanks for the help i will give it another shot ad also take a look at the tutorial also
15 years ago
If you dont mind can you explain this a lil further im very new to this and atm this one project has me pulling out










import java.util.Scanner;


public class Payroll {

public Payroll() {

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




// prompt for and input employee name
System.out.println( "Please enter the employee name:" );
String employeeName = input.nextLine(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hourly wage
System.out.println( "Please enter the employee hourly wage:" );
double hourlyWage = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hours worked
System.out.println( "Please enter the employee hours worked:" );
double hoursWorked = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line


System.out.println(); // outputs a blank line

System.out.println("Employee Name: " + employeeName);
System.out.println("Hourly Wage: " + hourlyWage);
System.out.println("Hours Worked: " + hourlyWage);



public void static main(String[] args){)
new Payroll();



// end method main


// end class Payroll
15 years ago
I seem to be getting this error message now after i figured out why it wasnt running.Any ideas or suggestions on how to correct this?

C:\jdk1.5.0_14\bin>javac Payroll.java
Payroll.java:51: illegal start of expression
public void static main(String[] args) {}
^
1 error

import java.util.Scanner;


public class Payroll {

public Payroll() {

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




// prompt for and input employee name
System.out.println( "Please enter the employee name:" );
String employeeName = input.nextLine(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hourly wage
System.out.println( "Please enter the employee hourly wage:" );
double hourlyWage = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hours worked
System.out.println( "Please enter the employee hours worked:" );
double hoursWorked = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line


System.out.println(); // outputs a blank line

System.out.println("Employee Name: " + employeeName);
System.out.println("Hourly Wage: " + hourlyWage);
System.out.println("Hours Worked: " + hourlyWage);

}

public void static main(String[] args) {}
new Payroll();

;
} // end method main


} // end class Payroll
15 years ago
my assignment called for me to Move implemenation out of main(String[ ] args). I thought this was what i was doing but it isnt i guess. Do you know where i might could look for information or ideas on how to accomplish this and my code still runs.
15 years ago
Thank you all for the much needed help. I read more on how packages from both sites that was listed by you guys.So now my error is gone Yay but my program fails to run even though it gives no errors.Any suggestions on why this might be happening?
15 years ago
I guess im a lil confused because i have the class files in the same directory which is the bin folder. Is this a bad idea?
15 years ago
I have been working on trying to get a project to run for 2 days but i receive the following error.Let me backup a lil. This is what my code looks like. I had no errors until my assignment called for me to Move implemenation out of main(String[ ] args). Any help or suggestions will be much appreciated.



package payroll;

import java.util.Scanner;


public class Payroll {



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




// prompt for and input employee name
System.out.println( "Please enter the employee name:" );
String employeeName = input.nextLine(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hourly wage
System.out.println( "Please enter the employee hourly wage:" );
double hourlyWage = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hours worked
System.out.println( "Please enter the employee hours worked:" );
double hoursWorked = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line


System.out.println(); // outputs a blank line

System.out.println("Employee Name: " + employeeName);
System.out.println("Hourly Wage: " + hourlyWage);
System.out.println("Hours Worked: " + hourlyWage);

// main method begins execution of Java Application
}
public static void main(String args[]) {


} // end method main


} // end class Payroll

Error

C:\jdk1.5.0_14\bin>java Payroll
Exception in thread "main" java.lang.NoClassDefFoundError: Payroll (wrong name:
payroll/Payroll)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:1
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
15 years ago
HERE IS THE CODE
C:\jdk1.5.0_14\bin>javac InventoryProgram.java
InventoryProgram.java:10: ';' expected
^
1 error


public class InventoryProgram{

public static void main(String[] args)

public String name;
public int itemNumber;
public int stockQuantity;
public double price;
public InventoryProgram(String name, int itemNumber, int stockQuantity, double price){
this.name = name;
this.itemNumber = itemNumber;
this.stockQuantity = stockQuantity;
this.price = price;
}

public String toString(){
return "CD Title: " + this.name + "\n" +
"Item Number: " + this.itemNumber + "\n" +
"Stock Quantity: " + this.stockQuantity + "\n" +
"Price: " + this.price + "\n";
}

public String getName(){
return this.name;
}

public void setName(String name){
this.name = name;
}

public int getItemNumber(){
return this.itemNumber;
}

public void setItemNumber(int itemNumber){
this.itemNumber = itemNumber;
}

public int getStockQuantity(){
return this.stockQuantity;
}

public void setStockQuantity(int stockQuantity){
this.stockQuantity = stockQuantity;
}

public double getPrice(){
return this.price;
}

public void setPrice(double price){
this.price = price;

} //end method main
} //end class InventoryProgram
16 years ago
I tryed adding one and still somehow manage to get that error.. So i must be having a lack of brain function moment.. Any help with this will be much appreciated
16 years ago