- #1
d3nat
- 102
- 0
Hi :)
I'm taking my first java course. I took two C++ courses last year, and I understand OOP pretty decently, but I cannot get this java program to work! And I'm beginning to get really frustrated because I can't find my mistake.
This is my class file:
package studentsjav;
__________
public class Students {
private double gpa;
private String name, major, address;
public Students() {
name="NoName";
major="NoMajor";
address="NoAddress";
ComputeGPA();
}
public void setName (String N) {
name=N;
}
public String getName(){
return name;
}
public void setMajor (String M) {
major=M;
}
public String getMajor (){
return major;
}
public void setAddress (String A) {
address=A;
}
public String getAdress() {
return address;
}
public double ComputeGPA () {
gpa = (Math.random()*3.5)+.5;
return gpa;
}
/* public String toString(){
String result=Double.toString(gpa);
return result;
}
*/
}
This is the driver file
package studentsjav;
public class StudentsJAV {
public static void main(String[] args) {
// TODO code application logic here
Students A = new Students();
A.setName("D3nat");
A.setMajor("Physics");
A.setAddress("Xville");
A.ComputeGPA();
//System.out.println(A);
}
}
Now, at the end of the driver file, I want to put
System.out.println(A);
and have it print my Student. It only prints the GPA.
Does anyone know why it won't print any of the other information?
I'm really at a loss.
Thank you.
I'm taking my first java course. I took two C++ courses last year, and I understand OOP pretty decently, but I cannot get this java program to work! And I'm beginning to get really frustrated because I can't find my mistake.
This is my class file:
package studentsjav;
__________
public class Students {
private double gpa;
private String name, major, address;
public Students() {
name="NoName";
major="NoMajor";
address="NoAddress";
ComputeGPA();
}
public void setName (String N) {
name=N;
}
public String getName(){
return name;
}
public void setMajor (String M) {
major=M;
}
public String getMajor (){
return major;
}
public void setAddress (String A) {
address=A;
}
public String getAdress() {
return address;
}
public double ComputeGPA () {
gpa = (Math.random()*3.5)+.5;
return gpa;
}
/* public String toString(){
String result=Double.toString(gpa);
return result;
}
*/
}
This is the driver file
package studentsjav;
public class StudentsJAV {
public static void main(String[] args) {
// TODO code application logic here
Students A = new Students();
A.setName("D3nat");
A.setMajor("Physics");
A.setAddress("Xville");
A.ComputeGPA();
//System.out.println(A);
}
}
Now, at the end of the driver file, I want to put
System.out.println(A);
and have it print my Student. It only prints the GPA.
Does anyone know why it won't print any of the other information?
I'm really at a loss.
Thank you.