Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 10-02-09   #1 (permalink)
Overclocker
 
MC-Sammer's Avatar
 
intel ati

Join Date: Oct 2007
Location: Home
Posts: 86

Rep: 2 MC-Sammer Unknown
Unique Rep: 2
Folding Team Rank: 658
Trader Rating: 0
Question Java assistance

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);
	}

}
earlier I tried leaving idNumber as a integer and then converting it to a String, but getPerson wouldn't let me do that.

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
4.21 GHz - 920 i7 D0

System: La Tigre
CPU
i7 920 D0 @ {Working on it}
Motherboard
ASUS P6T V2
Memory
12GB OCZ PC-12800
Graphics Card
Visiontek Radeon 4890
Hard Drive
x2 WD 500GB RAID 0
Sound Card
Onboard
Power Supply
Antec CP-850
Case
Antec 1200
CPU cooling
Thermalright IFX-14 w/ 2xSythe Slipstream 1900 RPM
GPU cooling
Stock
OS
Vista Ultimate x64
Monitor
ASUS 24"
MC-Sammer is offline I fold for Overclock.net   Reply With Quote
Old 10-03-09   #2 (permalink)
PC Gamer
 
Nhb93's Avatar
 
amd nvidia

Join Date: Aug 2009
Posts: 314

Rep: 18 Nhb93 Unknown
Unique Rep: 17
Trader Rating: 0
Default

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.

System: HAFaestus (Alienware ported into HAF 932)
CPU
AMD Athlon 64 X2 6000+
Motherboard
Foxconn nForce 590 SLI
Memory
4GB
Graphics Card
GeForce 8800 GTX
Hard Drive
250GB Seagate + 750GB WD
Sound Card
Onboard
Power Supply
HIPRO HP-W700WC3 LF 700W
Case
Cooler Master HAF 932
CPU cooling
TRUE + Ceramique + San Ace 120
GPU cooling
Stock
OS
Windows 7 Professional 64-bit/Windows XP 32-bit
Monitor
Samsung SyncMaster 930B
Nhb93 is offline   Reply With Quote
Old 10-03-09   #3 (permalink)
Intel Overclocker
 
dham's Avatar
 
intel ati

Join Date: May 2009
Location: North Carolina
Posts: 689

Rep: 45 dham is acknowledged by some
Unique Rep: 33
Trader Rating: 0
Default

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);
	}

}
this is the mockup of what you want to do.
Code:
Employee employee = new Employee();
employee.getPerson("Mark Jones");
System.out.println(employee.getName);
System.out.println(employee.getDeparment);
__________________
Quote:
Originally Posted by jshay View Post
How convenient, the warranty ends when the world ends.
Quote:
Originally Posted by slothfish View Post
So lifetime warranty then?

System: Main Digital Audio Workstation
CPU
Core i5 750 4.01ghz at 1.27v
Motherboard
MSI P55-GD80
Memory
G.SKILL 4GB DDR3 1600mhz
Graphics Card
Sapphire Radeon HD 5870 1GB
Hard Drive
Western Digital Caviar Black 500gb 32mb cache
Sound Card
Line 6 Guitar Port/Gear Box
Power Supply
Corsair HX750
Case
Antec Nine-hundred two
CPU cooling
Megahalem w/ Panaflo 114cfm
GPU cooling
Stock
OS
Windows 7 Ultimate 64
Monitor
22" Acer

Last edited by dham : 10-03-09 at 03:08 PM
dham is offline   Reply With Quote
Old 10-03-09   #4 (permalink)
Overclocker
 
MC-Sammer's Avatar
 
intel ati

Join Date: Oct 2007
Location: Home
Posts: 86

Rep: 2 MC-Sammer Unknown
Unique Rep: 2
Folding Team Rank: 658
Trader Rating: 0
Default

Well I had to do a ton more work, but I got it figured out, thanks for the suggestions!
__________________
I fold for team 37726
4.21 GHz - 920 i7 D0

System: La Tigre
CPU
i7 920 D0 @ {Working on it}
Motherboard
ASUS P6T V2
Memory
12GB OCZ PC-12800
Graphics Card
Visiontek Radeon 4890
Hard Drive
x2 WD 500GB RAID 0
Sound Card
Onboard
Power Supply
Antec CP-850
Case
Antec 1200
CPU cooling
Thermalright IFX-14 w/ 2xSythe Slipstream 1900 RPM
GPU cooling
Stock
OS
Vista Ultimate x64
Monitor
ASUS 24"
MC-Sammer is offline I fold for Overclock.net   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 05:44 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.09936 seconds with 8 queries