Welcome! Log In Create A New Profile

Advanced

spinning smiley sticking its tongue outDoes Java 6 have a problem?

Posted by 31557511 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
spinning smiley sticking its tongue outDoes Java 6 have a problem?
August 10, 2010 10:00PM
II downloaded the source code for the book from Mughal's website. Unfortunately some of my programs do not run. For example when I compile the program 7.2 on page 169 I get 39 errors. Is there a problem with the book. Now how do I learn please help because I want to complete the assignments as soon as possible. Another question is that will I lose marks if I solve a problem another way other than the one specified in the book since the book seem to have some errors in the content. Please help Doc.
avatar
Mac
Re: spinning smiley sticking its tongue outDoes Java 6 have a problem?
August 11, 2010 07:34AM
2nd part - you can solve it anyway you want.

It could be the version of Java - I'll check with Mr Masombuka.
Re: spinning smiley sticking its tongue outDoes Java 6 have a problem?
August 11, 2010 09:10AM
You don't say what errors you get but Program 7.2 uses EmployeeV3 class which is implemented in Program 7.1. In order to run 7.2 you must first compile 7.1 and make sure they are in the same directory.

Masombuka
Re: spinning smiley sticking its tongue outDoes Java 6 have a problem?
August 12, 2010 06:05PM
Thank you Doc and Sombu!

I get 2 errors when I first compile Program 7.1 with class EmployeeV3. The first error is in line 13 where it complains about the key word void. It says illegal start of expression.
It then complains about line 47 where it says ';' semi-colon expected but I think there should be a bracket. Please help!
Re: spinning smiley sticking its tongue outDoes Java 6 have a problem?
August 25, 2010 10:22AM
Post your code
Re: spinning smiley sticking its tongue outDoes Java 6 have a problem?
September 08, 2010 08:33PM
public class EmployeeV3 { // Assume that no constructors are declared.
// Field variables
public static void main(String[] args){

String firstName;
String lastName;
double hourlyRate;
boolean gender; // false means male, true means female

// Instance methods

// Assign values to the field variables of an employee.
void setState(String fName, String lName,
double hRate, boolean genderValue) {
firstName = fName;
lastName = lName;
hourlyRate = hRate;
gender = genderValue;
}

// Determines whether an employee is female.
boolean isFemale() { return gender; }

// Computes the salary of an employee, based on the number of hours
// worked during the week.
double computeSalary(double numOfHours) {
assert numOfHours >= 0 : "Number of hours must be >= 0";
double normalNumOfHours = 37.5;
double weeklySalary = hourlyRate * normalNumOfHours;
if (numOfHours > normalNumOfHours) {
weeklySalary += 2.0 * hourlyRate * (numOfHours - normalNumOfHours);
}
return weeklySalary;
}

// Prints the values in the field variables of an employee.
void printState() {
System.out.print("First name: " + firstName);
System.out.print("\tLast name: " + lastName);
System.out.printf("\tHourly rate: %.2f", hourlyRate);
if (isFemale()) {
System.out.println("\tGender: Female"winking smiley;
} else {
System.out.println("\tGender: Male"winking smiley;
}
}
}
}
Re: spinning smiley sticking its tongue outDoes Java 6 have a problem?
September 10, 2010 04:58PM
Dear Sombu and Doc,

I have already sorted out the above problem. I removed the main method and the last bracket. I then first compiled program 7.1 before compiling program 7.2 which has the main method and it runs as expected.

Thanx!
Sorry, only registered users may post in this forum.

Click here to login