View Full Version : Anyone good with java programming?


85f150
09-28-2005, 10:36 PM
I can't seem to find the prob but i suck at programming.............I won't lie it is for class but i am going nuts staring at the screen. I am getting the error can't resolve symbol.......it is for all the variables that are named hours_worked and pay_rate.

Don't pay much atten to the comments as it is all a mess.

This is what i am trying to do http://www.java-help.com/IntroProj01.htm



import java.io.*;

// The main method of this class can be used to convert temperatures
// from Fahrenheit to Celsius and Celsius to Fahrenheit. It supports
// keyboard input and demonstrates menu-driven processing.
// ----- Written by: Jon Huhtala

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

// Constants and variables needed for menu processing.

final int CALC_PAY = 1;
final int PAY_STAT = 2;
final int ABOUT = 3;
final int EXIT = 4;
int choice = 0;
int payroll_calc = 0;
int total_gross = 0;
int av_gross_pay = 0;

// This loop handles menu-driven processing. The loop will continue until
// the user chooses to exit.

do {

// Display the menu and get the user's choice.

System.out.println("----------------------------------------");
System.out.println("");
System.out.println(" Payroll Menu");
System.out.println("");
System.out.println("1 - Calculate Pay");
System.out.println("2 - Payroll Statistics");
System.out.println("3 - About");
System.out.println("4 - Exit");
System.out.println("");
System.out.print("Enter selection: ");
choice = Utility.readInt();
System.out.println("");



if (choice == CALC_PAY) {
System.out.print("Enter hours worked: ");
double hours_worked = Utility.readDouble();
System.out.print("Enter hourly wage: ");
double pay_rate = Utility.readDouble();
}
else if (hours_worked >= 40 && pay_rate >= 5.15) {
gross_pay = (hours_worked * pay_rate + 1.5 * pay_rate (hours_worked - 40));
System.out.println("Your gross pay is: " + gross_pay);
payroll_calc ++;
Utility.pressEnter();
System.out.println("");
}

else if (Hours_worked <= 40 && pay_rate >= 5.15) {
gross_pay = (Hours_worked * pay_rate);
System.out.println("Your gross pay is: " + gross_pay);
payroll_calc ++;
Utility.pressEnter();
System.out.println("");
}
else if (choice == PAY_STAT) {
System.out.println("Number of payroll calculations: " + payroll_calc);
System.out.println("Total gross pay for all employees" + total_gross);
}
else if (payroll_calc > 0) {
av_gross_pay = (total_gross / payroll_calc);
Utility.pressEnter();
System.out.println("");
}
else if (payroll_calc == 0) {
System.out.println("No payroll calculations have been made, please make a different choice.");
}
// This block processes a request to exit.

if (choice == ABOUT) {
System.out.println("Paul Immoos");
Utility.pressEnter();
System.out.println("");

}
else if (choice == EXIT) {
System.out.println("Exit requested");
Utility.pressEnter();
System.out.println("");
}

// This block processes an invalid menu selection.

else {
System.out.println("Invalid menu choice");
Utility.pressEnter();
System.out.println("");
}
} while (choice != EXIT);
}
}

// This class contains custom methods that support application processing.
// ----- Written by: Jon Huhtala

class Utility {
private static BufferedReader kb =
new BufferedReader(new InputStreamReader(System.in));

// Call this method to read an int value from the keyboard.

public static int readInt() {
Integer result = null;
while (result == null) {
try {
result = new Integer(kb.readLine());
}
catch(Exception err) {
System.out.print("INVALID int! Please try again: ");
}
}
return result.intValue();
}

// Call this method to read a double value from the keyboard.

public static double readDouble() {
Double result = null;
while (result == null) {
try {
result = new Double(kb.readLine());
}
catch(Exception err) {
System.out.print("INVALID double! Please try again: ");
}
}
return result.doubleValue();
}

// Call this method to read a String value from the keyboard.

public static String readString() {
String result = null;
while (result == null) {
try {
result = kb.readLine();
}
catch(Exception err) {
System.out.print("INVALID String! Please try again: ");
}
}
return result;
}

// Call this method to ask the user to press the ENTER key to continue.

public static void pressEnter() {
System.out.print("Press ENTER to continue...");
readString();
}
}

darb
09-28-2005, 10:49 PM
You have gross_pay declared as an int, and the other two a double. Not familiar with your compiler, but this may be the problem. You probably need to either explicitly convert your equation to int, or declare gross as a double.

brad

hmthesing
09-28-2005, 11:15 PM
I see that "gross_pay" isn't even declared as a variable. Only "av_gross_pay".

darb
09-28-2005, 11:24 PM
You're right...I didn't even notice that. That's probably it. I think I looked at the other gross declarations. pay_rate is still a double, and av_gross_pay and others are ints. There will probably still be problems there.

Even if they don't show up as code errors, they're still logic bugs that, on a larger scale, can cause HUGE headaches.

brad

MyFullSize
09-28-2005, 11:49 PM
If you want it converted to ASP, Im your man! :thumbup

Otherwise, I gave up on Java/JavaScript a *long* time ago. Cross platform yes, resource hog and theif, yes too.

welndmn
09-29-2005, 12:37 PM
If you want it converted to ASP, Im your man! :thumbup

Otherwise, I gave up on Java/JavaScript a *long* time ago. Cross platform yes, resource hog and theif, yes too.
x2, Java is so 5 years ago, sadly my new company is VERY java, I am picking it back up again

BikerPepe`
09-30-2005, 01:07 AM
so very sad to read... Javascript is an integral piece of the AJAX technology that is already starting to change the way software is implemented and used.

For the record I'm only the operations manager... not a programmer, but from what I see my guys doing, OOP in Java & PHP is the way to go for speed/performance over the web.

Shameless Plug: http://www.datamosaics.com
FYI: The main site is standard coding, NOT the technology that drives our OnDemand Applications.


ASP = :uke:
:goodfinge

Broncobob
09-30-2005, 01:18 AM
^^ agreed.

ScorpionBoy
09-30-2005, 12:18 PM
JAVA is sooo not 5 years ago. You better figure it out fast, most coding is going this direction. Make sure you are a baddass at J2EE.

hmthesing
09-30-2005, 12:32 PM
What scares me is that they're still teaching BASIC. :shocked

ScorpionBoy
09-30-2005, 12:37 PM
That's probably no big deal, but should be avoided because I think it has 'goto' statements which are not helpful at all. I cut my teeth on some wierd little pasqal language just for one class. those simple little languages can be very good tools for learning conditional logic.

MyFullSize
09-30-2005, 01:09 PM
ASP.net is pretty fast.... just my .02....

85f150
10-03-2005, 12:28 PM
I hate programming in general, but it is required. I already had C++ and this is pretty close..


BTW, i went back trying to read his notes.....ends up this is supposed to be with switch statements and not else/if..........................so now that i feel stupid hopefully that will fix my probs.

hmthesing
10-03-2005, 12:32 PM
That how it was with me...had C++ and then switched to Java. Very easy to convert over. Java is so much easier than C++.

ScorpionBoy
10-03-2005, 01:28 PM
JAVA was purposefully engineered for ease of transition from C++ and it definitely easier to use...no explicit pointers etc.

hmthesing
10-03-2005, 01:32 PM
Yeah, I think I got a C grade, maybe a B in C++, went to Java, never got lower than an A.

85f150
10-05-2005, 12:59 AM
ok guys.....i have fixed everything and converted it to switch statements........my issue now is i can't figure out how to add to a variable... take this snippet for example

switch (transCode) {
case 1:
System.out.print("Enter Hours Worked: ");
double hours_worked = Utility.readDouble();
System.out.print("Enter Pay Rate: ");
double pay_rate = Utility.readDouble();
if (hours_worked >= 40 && pay_rate >= 5.15) {
gross_pay = (int) (40 * pay_rate + 1.5 * (hours_worked - 40));
System.out.println("Your gross pay is: " + gross_pay);
payroll_calc ++;
gross_pay + total_gross_pay;
Utility.pressEnter();
System.out.println("");
}
else if (hours_worked <= 40 && pay_rate >=5.15) {
gross_pay = (int) (hours_worked * pay_rate);
System.out.println("Your gross pay is: " + gross_pay);
payroll_calc ++;
gross_pay + total_gross_pay;
Utility.pressEnter();
System.out.println("");
}
break;

the 2 lines where it says gross_pay + total_gross_pay; i need to add gross_pay to total_gross_pay and keep a running total. But i have no clue as to how

thanks

ScorpionBoy
10-05-2005, 01:59 AM
double grandTotal = 0;//declared outside of switch

grandTotal = grossPay + totalGrossPay;

also, you don't want to cast your calcs to int (int) like that, you will truncate your numbers.

gross_pay = (hours_worked * pay_rate);