Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

CS F213- Object Oriented Programming

Student Grade (Examples)

1 $vi StudentTester.java
1 class Student {
2
3 String name;
4 int age;
5 float t1, t2, compre, total;
6
7 char grade;
8
9 public Student ( String n, int a) {name = n; age = a;}
1
0
1
public void setT1 (float aT1) { t1 = aT1; }
1 public void setT2 (float aT2) { t2 = aT2; }
1 public void setCompre (float aCompre) { compre = aCompre; }
2
1
3 public void calcTotal() { total = t1 + t2 + compre; }
1 public float getTotal() { return total; }
4
public void calcGrade(float cutOffA, float cutOffB, float cutOffC) {
if ( total >= cutOffA ) { grade = 'A';
} else if ( total >= cutOffB ) { grade = 'B';
} else if ( total >= cutOffC ) { grade = 'C';
} else { grade = 'D';
}
}

public char getGrade() { return grade; }


void display() {
System.out.println ("I am " + name + " of age" + age);
System.out.println ("My grade is " + grade);
}
}

public class StudentTester {


public static void main (String[] args) {
Student s1 = new Student("abc", 10);
s1.setT1(20); // s1.t1 = 20;
s1.setT2(25);
s1.setCompre(30);
s1.calcTotal();
s1.calcGrade(70, 60, 50);
//char grade = s1.getGrade();
s1.display();
}
}
$javac StudentTester.java

$java StudentTester

You might also like