|
|
|
#1 (permalink) | |||||||||||||
|
Overclocker
|
I'm trying to make a console application which displays a person's name, their ID, department, and position.
I'm not going to lie, this is for a class, and I could probably figure out a much easier way to do the same thing, but I like to make things a little harder so I can learn more. I'm not asking for someone to give me an answer, unless of course you want to, I just need some assistance getting certain parts to function properly. Code:
public class fetchEmployee {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Employee getPerson;
Employee SetPerson;
String name;
int idNumber;
String department;
String position;
String idNumber2 = Integer.toString(idNumber);
System.out.println(name +" "+ idNumber2 + " " + department + " " + position);
}
}
Code:
public class Employee {
public String name;
public int idNumber;
public String department;
public String position;
public String idNumberTwo;
String idNumber2 = Integer.toString(idNumber);
public static String getPerson(String name, String idNumberTwo, String department, String position)
{ //getPerson start
if (name == "Susan Meyers")
{
name = "Susan Meyers";
idNumberTwo = "47899";
department = "Accounting";
position = "Vice President";
}
else if (name == "Mark Jones")
{
name = "Mark Jones";
idNumberTwo = "39119";
department = "IT";
position = "Programmer";
}
else if (name == "Joy Rogers")
{
name = "Joy Rogers";
idNumberTwo = "81774";
department = "Manufacturing";
position = "Engineer";
}
return person(name, idNumberTwo, department, position);
} //getPerson end
public String SetPerson()
{
name = "Susan Meyers";
Employee.getPerson(name, idNumberTwo, department, position);
System.out.println(name +" "+ idNumber + " " + department + " " + position);
}
}
if it helps, I'm using Eclipse for an IDE, and right now I'm just trying to get the second set of code working, then I'll work on the first set.
__________________
I fold for team 37726![]()
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
PC Gamer
|
I'm not sure completely is this will work, but instead of SetPerson, I'd suggest trying making a call to "Employee.toString". toString is pretty much the standard for making a call to an object like Employee. You need to return the same info as SetPerson, but Java knows how to handle the.toString method to print out the results. Hope that helps.
__________________
|
|||||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
Intel Overclocker
![]() |
Hey man. First things first. Testing strings will require the equals method.
So name.equals("name"); name == "name" is legal but it will never return what you want it to return. Also why are you wanting to convert the integer to a string. What you need to do is have separate methods to return each value and set each value. Your variables(members) should all be private and use public getters and setters for each value. You do not want a string function to return everything including int values(which your right you will have to convert to string to return them) note: this is just a mock up. Your function names are wrong and really this isn't the correct way to do it. Also use netbeans ide. Much better imo. Eclipse is good if you get the payed for version. Code:
public class Employee {
private String name;
private int idNumber;
private String department;
private String position;
private String idNumberTwo;
public String getPerson(String name) {
if (name.equals("Susan Meyers")) {
this.name = "Susan Meyers"; //you dont have to use this but it explicitly refers to the current object
this.idNumberTwo = 47899;
this.department = "Accounting";
this.position = "Vice President";
}
else if (name.equals("Mark Jones")) {
name = "Mark Jones";
idNumberTwo = 39119;
department = "IT";
position = "Programmer";
}
else if (name.equals("Joy Rogers")) {
name = "Joy Rogers";
idNumberTwo = 81774;
department = "Manufacturing";
position = "Engineer";
}
}
public String SetPerson() {
name = "Susan Meyers";
Employee.getPerson(name);
System.out.println(name +" "+ idNumber + " " + department + " " + position);
}
}
Code:
Employee employee = new Employee();
employee.getPerson("Mark Jones");
System.out.println(employee.getName);
System.out.println(employee.getDeparment);
__________________
Last edited by dham : 10-03-09 at 03:08 PM |
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
Overclocker
|
Well I had to do a ton more work, but I got it figured out, thanks for the suggestions!
__________________
I fold for team 37726![]()
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|