Add a (non-static) method to the Person class that adds..."insert string or integer change"...to Person object. The name of this method should be birthday()/phd(). The return type is void. The method has no parameters.
I am getting the following error after I have finished coding and not sure what to adjust as I have moved stuff around to no avail. Any advice? Below is the Error recieved for lines 16 and 17.
PersonCommand.java:24: error: non-static method phd() cannot be referenced from a static context
PersonCommand.java:24: error: non-static method birthday() cannot be referenced from a static context
import javax.swing.JOptionPane;
public class PersonCommand {
public static void main(String[ ] args) {
int age1 = Integer.parseInt(args[1]);
//creates one person objects
Person person1 = new Person(args[0], age1);
//Prints the first JPane with relative data fields
String display1 = person1.toString();
JOptionPane.showMessageDialog(null, display1);
//Calls phd and birthday method
Person.birthday();//Calls birthday method
Person.phd();//Calls phd method
JOptionPane.showMessageDialog(null, display1);
}//end of class
}
/*Stores the name and age of the person*/
class Person{
//data fields that store each object's data
private String name;
private int age;
/** Constructor - Used To Create EAch Object & Initialize DAta Fields.
* @param n1 is the Persons name
* @param a1 is the Persons age*/
public Person(String n1, int a1){
name = n1;
age = a1;
}
//Used to Display The Data Stored In EAch Object's DAta Field.
public String toString(){
String personString = name + " is " + age + " years old.";
return personString;
}
//Method used to display age
public void phd(){
String n1 = "Dr. " + name;
return;
}
//Method used to display age
public void birthday(){
Integer a1 = age + 1;
return;
}
}

New Topic/Question
Reply



MultiQuote





|