My problem is, when i set: ProfileInformation p = new ProfileInformation(\"A\",
ID: 3628591 • Letter: M
Question
My problem is, when i set: ProfileInformation p = new ProfileInformation("A", "Name");Then try to get the location or phone number via: p.getLocation or p.getPhoneNumber. I keep getting an error!?
Thanks will rate.
public class ProfileInformation
{
/**
* This is a javadoc comment.
*@param args User-defined command line arguments (not used).
*/
// Declare instance variables here
private String firstName, lastName;
private boolean isSet;
private String locationName, aNumber; //Location name, number
private String location, phoneNumber;
private int ageInYears;
private int age, isOnline, status;
private static final int OFFLINE = 0,> // Constuctor
/**
* Sets the first and last name.
*@param first Sets the formal paramater for "first" name.
*@param last Sets the formal paramater for "last" name.
*/
public ProfileInformation(String first, String last)
{
firstName = first;
lastName = last;
location = "Not specified";
phoneNumber = "none";
age = 0;
status = OFFLINE;
}
// Methods
/**
* Sets the location of the user.
*@param aLocationName Sets the formal paramater for
*the user's location.
*/
public void setLocation(String locationName) //location name
{
location = locationName; //location name
}
/**
* Sets the age of the user.
*@param ageInYears Sets the formal paramater for
*@return Returns the value "true" for ageInYears.
*/
public boolean setAge(int ageInYears) {
boolean isset = false;
if (ageInYears > 0) {
age = ageInYears;
isSet = true;
}
return isSet;
}
/**
* Sets the age of the user.
*@param aNumber the phone number.
*/
public void setPhoneNumber(String aNumber)//number
{
phoneNumber = aNumber; //number
}
/**
* Sets the age of the user.
*@return returns the users age in years.
*/
public int getAge() {
return ageInYears;
}
/**
* Sets the user's location.
*@return Returns the users location.
*/
public String getLocation() {
return location; //location name.
}
/**
* Sets the user offline.
*/
public void logOff() {
status = OFFLINE;
}
/**
* Sets the user online.
*/
public void logOn() {
status = ONLINE;
} /**
* Sets the user's location.
*@return Returns the users location.
*/
public String getPhoneNumber() {
return phoneNumber; //number
}
// toString method (for String output)
/**
* Prints out the users information.
@return returns the output of the user.
*/
public String toString()
{
String output = "Name: " + firstName + " "
+ lastName + " ";
output += "Location: " + location + " ";
output += "Age: " + age + " ";
output += "Phone number: " + phoneNumber + " ";
output += "Status: ";
if (status == OFFLINE)
{
output += "Offline";
}
else
{
output += "Online";
}
return output;
}
}
Explanation / Answer
The methods exist. Are you remembering to use parentheses to call the method?
ProfileInformation p = new ProfileInformation("A", "Name");
System.out.println(p.getLocation());
System.out.println(p.getPhoneNumber());
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.