How to do calculations and print out to console?
in
Programming Questions
•
6 months ago
Im having trouble printing out things to the console. my code is supposed to average out a students 2 test average and print it out to the console. I cant seem to find out what i did wrong. Please help. Thanks. Below is my code.
void setup()
{
new student("ben", 75, 60, 5);
}
{
new student("ben", 75, 60, 5);
}
void printStudent(student name)
{
println("Name:" +name.getName());
println("Exam 1 Grade:" + name.getExam1());
println("Exam 2 Grade:" + name.getExam2());
println("Bonus:" + name.getBonus());
println("GPA:" + name.calcGPA());
}
{
println("Name:" +name.getName());
println("Exam 1 Grade:" + name.getExam1());
println("Exam 2 Grade:" + name.getExam2());
println("Bonus:" + name.getBonus());
println("GPA:" + name.calcGPA());
}
class student
{
String name;
float e1, e2;
int bonus;
{
String name;
float e1, e2;
int bonus;
student(String n, float ex1, float ex2, int b)
{
name=n;
e1=ex1;
e2=ex2;
bonus=b;
}
float calcGPA()
{
float gpa= (e1+e2+bonus)/2;
return gpa;
}
float getExam1()
{
return e1;
}
float getExam2()
{
return e2;
}
float getBonus()
{
return bonus;
}
String getName()
{
return name;
}
void setExam1(float e)
{
e1=e;
}
void setExam2(float e)
{
e2=e;
}
void setBonus(int b)
{
bonus=b;
}
}
{
return e1;
}
float getExam2()
{
return e2;
}
float getBonus()
{
return bonus;
}
String getName()
{
return name;
}
void setExam1(float e)
{
e1=e;
}
void setExam2(float e)
{
e2=e;
}
void setBonus(int b)
{
bonus=b;
}
}
1