Argument entered: Jessica 22
Pane 1
Jessica is 22 years old.
Pane 2
Dr. Jessica is 23 years old.
For some reason after I recall the toString method, the output is still not changed. Am i calling the phd/birthday method wrong or is the phd/birthday methods coding incorrectly?
Thanks,
import javax.swing.JOptionPane;
public class PersonCall {
public static void main(String[ ] args) {
//Parse Integers entered on the command-line
int age1 = Integer.parseInt(args[1]);
//creates two persons 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
person1.birthday();//Calls birthday method
person1.phd();//Calls phd method
display1 = person1.toString();//Calls toString to refresh new data.
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;
}
//Method used to display age
public void birthday(){
Integer a1 = age + 1;
}
}

New Topic/Question
Reply



MultiQuote





|