• Steam recently changed the default privacy settings for all users. This may impact tracking. Ensure your profile has the correct settings by following the guide on our forums.

Help!

Status
Not open for further replies.

Seth

MD Party Room
Code:
public class person 

{ 
 private String name; 
 private String adress; 
  private int age; 
   private String phone; 
	
	public person()
	{ name = "";
	  adress = "";
	  phone = "";
	  age =0;
	  }
	  
	  public person( String myname, String myaddress, int myage , String myphone)
	  
	  {
	  name = myname;
	 adress = myaddress;
	  age = myage;
	  phone =myphone;
	  }
	  
	  public void setname(String myname){
	  
	 name=myname; 
	 }
	  public void setaddress(String myaddress){
	 adress = myaddress; 
	  }
	  public void setage( int age){
	  age = myage;
	  }
	  public void setphone( String myphone){
	  phone = myphone;
	  }
	  
	  public String getname();
	  {return name;}
	  public String getaddress(){
	  
	  return adress;
	  }
	  public String getphone(){
	  return phone;
	  }
	  public int getage() {
	  return age;
	  }
	  }

This is what I have so far in my class and I dont understand what do to when I get this error

person.java:33: cannot find symbol
symbol : variable myage
location: class person
age = myage;
^
person.java:39: missing method body, or declare abstract
public String getname();
^
person.java:40: return outside method
{return name;}
^
3 errors

How the hell do I fix it?
 

Ahadiel

M for Mike
Code:
public class person { 
	private String name; 
	private String address; 
	private int age; 
	private String phone; 
	
	public person() { 
		name = "";
		address = "";
		phone = "";
		age = 0;
	}
	  
	public person(String myname, String myaddress, int myage, String myphone) {
		name = myname;
		address = myaddress;
		age = myage;
		phone = myphone;
	}
	  
	public void setname(String myname) {
		name = myname; 
	}

	public void setaddress(String myaddress) {
		address = myaddress; 
	}
	
	public void setage(int myage) {
		age = myage;
	}
	
	public void setphone(String myphone) {
		phone = myphone;
	}
	  
	public String getname() {
		return name;
	}
	
	public String getaddress() {  
		return address;
	}
	  
	public String getphone() {
		return phone;
	}
	
	public int getage() {
		return age;
	}
}

Not sure about the first error, but the others should be fixed. I also fixed your spacing/tabbing/braces so it's easier to read (at least imo).
 

karnbmx

ceebs. :)
For Error 1:

You can't assign Private variables to public variables. You can only access private variables through its methods.

EDIT: By that I mean that you can't assign private int age to int myage because they have different access rights. Either change one of them to public or change your myage variable to private and access it that way.
 

Seth

MD Party Room
wait I thought it can be both like when I did the whole

"public person() {
age = 0;"

and it was also private with the whole

public class person {
private int age;
 

Chathurga

Active Member
That is the WORST formatting I have ever seen. Seriously man, how did you write it like that?

Edit: Just read the entire code and I actually feel angry, please stop coding before someone has to co-op with you.
 

Seth

MD Party Room
Kinda have to I taking a intro to java class lol
 

Moca

New Member
Kinda have to I taking a intro to java class lol

Well, since you are new to Java, I'll give you a tip to help you and so that you won't get attacked when asking for help about your code.

FORMAT YOUR CODE. ;)

It makes it readable for you and for anyone else that has to read your code. Code looks cleaner when indented properly and blocks of code are easier to read that way.
 

Abe Froeman

Gamer Dad
Enforcer Team
Why are you taking a class like this when you can't spell or use syntax to save your life? If I held a gun to your head, you couldn't properly write three sentences.
 

Seth

MD Party Room
All my professor really cares about atm is that it complies and does the task at hand and that what i am focusing on, it homework after it turned in and I get a grade for it I could care less about how neat my code looks. Beside my code seems pretty readable to me...
 

Sousanator

Shockingly Delicious
All my professor really cares about atm is that it complies and does the task at hand and that what i am focusing on, it homework after it turned in and I get a grade for it I could care less about how neat my code looks. Beside my code seems pretty readable to me...
When you ask us for help, we care
 

Seth

MD Party Room
Well anyway The prolem fixed it self when I made a new class file so this can be closed now, thanks for the load of help guys /s
 

Moose

Meta Moose
Well anyway The prolem fixed it self when I made a new class file so this can be closed now, thanks for the load of help guys /s

Don't be so stupid. Any decent programmer will sensibly indent and format any code they write... I'm not even going to say why, it's self-explanatory.

Try it, if you dare.
 
Status
Not open for further replies.
Top