static message error from two non static classes
I have 3 classes. StudentLab(which has main), Student and Contact.
Contact - code:
import javax.swing.JOptionPane;
public class Contact
{
private String street, city, state, zip, phone, email;
public Contact()
{
street = "";
city = "";
state = "";
zip = "";
phone = "";
email = "";
}
public void setContact()
{
String input = JOptionPane.showInputDialog("Enter the students street address:");
street = input;
String input1 = JOptionPane.showInputDialog("Enter the students city:");
city = input1;
String input2 = JOptionPane.showInputDialog("Enter the students state:");
state = input2;
String input3 = JOptionPane.showInputDialog("Enter the students zip");
zip = input3;
String input4 = JOptionPane.showInputDialog("Enter the students phone number:");
phone = input4;
String input5 = JOptionPane.showInputDialog("Enter the students email:");
email = input5;
}
public String getAddress()
{
setContact();
String address;
address = "";
address = street + ", " + city + ", " + state + ", " + zip;
return address;
}
}
Student - Code:
import javax.swing.JOptionPane;
import java.text.*;
/**
* Define state of an Student Name and GPA
*/
public class Student
{
// Define state of an employee with name and salary
private String name; //student name
private double gpa; // Student salary
private double fin, midt, q1, q2, q3, q4; //student grades
private Contact contactInfo = new Contact();
private String address;
/** 0-arg constructor
*/
public Student()
{
name = "noName";
gpa = 0.0;
address = null;
}//end 0-arg constructor
/**2-arg constructor
*
*/
public Student(String nameVal, double GPAVal)
{
setName(nameVal);
setGPA(GPAVal);
setContactInfo();
}//end 2-arg constructor
public void setName(String stuName)
{
name = stuName;
}//end setName
public void setGPA(double stuGpa)
{
gpa = stuGpa;
}//end setGpa
public void setContactInfo()
{
Contact.getAddress();
}
(if I put just getAddress() I get the error -"Student.java": cannot find symbol; symbol : method getAddress(), location: class Student at line 51, column 13
In the setContactInfo()
if i use getAddress() or setContact()or any method call from Student to Contact
I get the message
"Student.java": non-static method getAddress() cannot be referenced from a static context at line 51, column 21
the problem I have is neather class has any static methods in them. Due to requirements with the program I am not allowed to call the getAddress or setContact from the main method. It must come from the Student class.
I don't understand what I am doing wrong.
Please help.

