Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Gradable Interface Lab In JAVA jGrasp Create a new folder to save all of your wo

ID: 3853693 • Letter: G

Question

Gradable Interface Lab

In JAVA jGrasp

Create a new folder to save all of your work. Define two separate classes that both implement the Gradeable interface.

public interface Gradable

{

public double getPercent();

public boolean isPassing();

}

1) The Student class will represent a student and the grade that he/she has in a class. This will be a different student class from the one you wrote in the “Back To School” lab so start with a blank Java file. The class will take in test scores and be able to compute the grade. A student is passing if their test average is greater than or equal to 60% Student has the following methods:

      a. A constructor that takes in a String representing the name of the student

      b. public void addTestScore(double score) which takes in a score that the student got on a test

      c. public String getName() returns the name of the student and any other methods required by the interface

2) The DriversEd class will represent a student taking a Driving test. The DriversEd class will NOT inherit from the Student class for this lab. In this driving test the students start out with 100 points, and are deducted points when they make mistakes. If a student loses more than 15 points, then they fail.

DriversEd has the following methods:

     a. A constructor that takes in a String representing the name of the person taking the test

     b. public void deductPoints(int num) which will deduct points from the total

     c. public String getName() returns the name of the person taking the test

3) Download the GradableRunner.java file from Blackboard to test your code.

Explanation / Answer

Gradable interface: /*Gradable.java */
_________________

public interface Gradable
{
public double getPercent();
public boolean isPassing();
}

Student Class: /*Student.java */
____________

import java.util.ArrayList;


public class Student implements Gradable{

   String sname;
   char grade;
   int count = 0;
   ArrayList<Double> al = new ArrayList<Double>();
  
   public Student(String sname){
       this.sname = sname;
   }
   public void addTestScore(double score){
       count++;
       al.add(score);
   }
   public String getName(){
       return sname;
   }
  
   @Override
   public double getPercent() {
       double sum = 0,avg = 0;
       for(double sc : al){
           sum += sc;
       }
       avg = sum / count;
       return avg;
   }

   @Override
   public boolean isPassing() {
       if(getPercent()>=60)
           return true;
       else
           return false;
   }

}

DriversEd Class: /*DriversEd.java*/
______________


public class DriversEd implements Gradable {
   String pname;
   int total = 100;
  
   public DriversEd(String pname){
       this.pname = pname;
   }
   public void deductPoints(int num){
       total = total - num;
   }
   public String getName(){
       return pname;
   }
  
   @Override
   public boolean isPassing(){
       if(total<85)
           return false;
       else
           return true;
   }
  
   @Override
   public double getPercent() {
       return total;
   }
}

GradableRunner Class: /*GradableRunner.java*/
____________________

public class GradableRunner
{
public static void main(String[] args)
{
Student John = new Student("John");
Student Paul = new Student("Paul");
  
DriversEd george = new DriversEd("George");
DriversEd ringo = new DriversEd("Ringo");
  
  
John.addTestScore(94.5);
John.addTestScore(45);
John.addTestScore(29);
John.addTestScore(99);
  
Paul.addTestScore(74);
Paul.addTestScore(82);
Paul.addTestScore(0);
Paul.addTestScore(71);
  
george.deductPoints(5);
george.deductPoints(4);
george.deductPoints(7);
  
ringo.deductPoints(1);
ringo.deductPoints(9);
ringo.deductPoints(2);

System.out.print(John.getName()+" has a "+John.getPercent()+" percent and ");
if(John.isPassing())
System.out.println("is passing");
else
System.out.println("isn't passing");
  
  
System.out.print(Paul.getName()+" has a "+Paul.getPercent()+" percent and ");
if(Paul.isPassing())
System.out.println("is passing");
else
System.out.println("isn't passing");
  
  
System.out.print(george.getName()+" has a "+george.getPercent()+" percent and ");
if(george.isPassing())
System.out.println("is passing");
else
System.out.println("isn't passing");
  
System.out.print(ringo.getName()+" has a "+ringo.getPercent()+" percent and ");
if(ringo.isPassing())
System.out.println("is passing");
else
System.out.println("isn't passing");
  
}
}

Sample Input and output:
_____________________

John has a 66.875 percent and is passing
Paul has a 56.75 percent and isn't passing
George has a 84.0 percent and isn't passing
Ringo has a 88.0 percent and is passing

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote