• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Need some java help

Sainix

Well-Known Member
Aug 27, 2010
158
2
Hey guys taking a java class and i am having trouble trying to get this to work.

need to Creat a class called Employee that includes three instance variabels, a first name (type string), a last name (type string) and a monthly salary (double). provide a constructor that initializes the three instance variables. provide a set and a get method for each instance variable. if the monthly salary is not positive, do not set its value write a test application named EmployeeTest that demonstrates class Employee's capabilities. Creat two employee objects and display each objects yearly salary. Then give each Employee a 10% raise and display each Employee's yearly salary agian.

So that is the problem and so far i have got

class Employee{

// data vector
String fn;
String ln;
double s;

// constructor
public Employee(String f, String l, double sal) {
fn = f;
ln = l;
s = sal;
}

// set procedure
void setFirst(String fNew) {
fn = fNew;
}
void setLast(String lNew) {
ln = lNew;
}
void setSal(double sNew) {
s = sNew;
}

//get function
String getFirst(){
return fn;
}
String getLast(){
return ln;
}
String getSalary(){
return s;
}
}

and for the test i have

public class EmployeeTest {
public static void main(String [] args){
Employee e1 = new Employee();
Employee e2 = new Employee("John","Pimpson",1.00);
System.out.printf("%s\t%s\t%f\n", e2.getFirst(),e2.getLast(),e2.getSalary());
System.out.printf("%s\t%s\t%f\n", e1.getFirst(),e1.getLast(),e1.getSalary());
e1.setFirst("John 5");
e1.setLast("Player");
e1.setSalary(10.00);
System.out.printf("%s\t%s\t%f\n", e1.getFirst(),e1.getLast(),e1.getSalary());
e.raiseSalary(1.1);
}
}

now im just stuck and trying to read threw my book for more info but if someone who knows java could maybe lend me a hand with this i would be greatful since this is only my first week in class.
 
Stuck on getting it to run, watched some youtube videos and came up with this

Public Class Employee{

// data vector
Private String firstName;
Private String lastName;
Private Double salaryValue;

// constructor
public Employee(String firstNameParameter, String lastNameParameter, Double salaryValueParameter)
{
firstName = firstNameParameter;
lastName = lastNameParameter;
if (doubleSalaryValue < 0)
salaryValue = 0.0
else
salaryValue = salaryValueParameter;
}

// set methods
void setFirstName(String firstNameParameter)
{
firstName = firstNameParameter;
}

void setLastName(String lastNameParameter)
{
lastName = lastNameParameter;
}

void setSalaryValue(Double doubleSalaryValue)
{
if (doubleSalaryValue < 0)
salaryValue = 0.0
else
salaryValue = doubleSalaryValue;

}

//get function
String getFirstName()
{
return firstName;
}
String getLastName()
{
return lastName;
}
Double getSalaryValue()
{
return salaryValue;
}


} //End Class

----------

class EmployeeTest
{
public static void main(String [] args)
{
String temp;
Double temp2;
Double temp3;
Employee EmployeeoneObject = new Employee("Bob","Bobson",10.0);
Employee EmployeetwoObject = new Employee("John","Pimpson",36.0);

temp = EmployeeoneObject.getFirstName();
System.out.print(temp);
temp = EmployeeoneObject.getLastName();
System.out.print(" ");
System.out.print(temp);
System.out.print("'s salary is ");
temp2 = EmployeeoneObject.getSalaryValue();
System.out.print(temp2);
System.out.print("/n");

temp = EmployeetwoObject.getFirstName();
System.out.print(temp);
temp = EmployeetwoObject.getLastName();
System.out.print(" ");
System.out.print(temp);
System.out.print("'s salary is ");
temp2 = EmployeetwoObject.getSalaryValue();
System.out.print(temp2);
System.out.print("/n");

temp2 = EmployeeoneObject.getSalaryValue();
temp3 = temp2 * 1.1;
EmployeeoneObject.setSalaryValue(temp3);

temp2 = EmployeetwoObject.getSalaryValue();
temp3 = temp2 * 1.1;
EmployeetwoObject.setSalaryValue(temp3);

temp = EmployeeoneObject.getFirstName();
System.out.print(temp);
temp = EmployeeoneObject.getLastName();
System.out.print(" ");
System.out.print(temp);
System.out.print("'s salary is ");
temp2 = EmployeeoneObject.getSalaryValue();
System.out.print(temp2);
System.out.print("/n");

temp = EmployeetwoObject.getFirstName();
System.out.print(temp);
temp = EmployeetwoObject.getLastName();
System.out.print(" ");
System.out.print(temp);
System.out.print("'s salary is ");
temp2 = EmployeetwoObject.getSalaryValue();
System.out.print(temp2);
System.out.print("/n");
}

}


When ever i try to javac Employee or javac EmployeeTest in command prompt i get a message saying

error: Class names, 'Employee', are only accepted if annotations explicitly requested
1 error

same thing for employeetest

Any ideas?
 
Upvote 0
Did you include the .java part of the file names for each file?

you gotta do javac Employee.java in order for it to compile, IIRC....

ROFL OMG how did i forget that haha must be that sleepy dammm
Thank you =p

kk now i get 13 errors....=[

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\USER>e:





E:\>javac Employee.java
Employee.java:1: class, interface, or enum expected
Public Class Employee{
^
Employee.java:5: class, interface, or enum expected
Private String lastName;
^
Employee.java:6: class, interface, or enum expected
Private Double salaryValue;
^
Employee.java:9: class, interface, or enum expected
public Employee(String firstNameParameter, String lastNameParameter, Dou
ble salaryValueParameter)
^
Employee.java:12: class, interface, or enum expected
lastName = lastNameParameter;
^
Employee.java:13: class, interface, or enum expected
if (doubleSalaryValue < 0)
^
Employee.java:17: class, interface, or enum expected
}
^
Employee.java:23: class, interface, or enum expected
}
^
Employee.java:28: class, interface, or enum expected
}
^
Employee.java:37: class, interface, or enum expected
}
^
Employee.java:43: class, interface, or enum expected
}
^
Employee.java:47: class, interface, or enum expected
}
^
Employee.java:51: class, interface, or enum expected
}
^
13 errors

E:\>
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones