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: 3861659 • 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

Answer ->

-------------------------------------------------------------------------------------------------------------------------------------------------

package my_chegg_package;

public interface Gradable {
  
   double getPercent();

   boolean isPassing();
}

-----------------------------------------------------------------------------------------------------------------------------------------------

package my_chegg_package;

public class Student implements Gradable {
   private String name;
   private double totalScore;
   private double percent;
   private int count;
  
   public Student(String name)
   {
       this.name=name;
       totalScore=0;
       count=0;
   }
   public String getName(){
       return name;
   }
  
   public void addTestScore(double score)
   {
       totalScore = totalScore + score;
       count=count+1;
   }
   @Override
   public double getPercent() {
       percent = (totalScore/count);
       return percent;
   }
   @Override
   public boolean isPassing() {
       if(percent >= 60)
       {
           return true;
       }
       else
       {
       return false;
   }
   }
}

---------------------------------------------------------------------------------------------------------------------------------------------

package my_chegg_package;

public class DriversEd implements Gradable{
   private String name;
   private int startingScorePoints;
   private int totalDeductPoints ;
   private int percent;
   public DriversEd(String name)
   {
       this.name=name;
       startingScorePoints = 100;
       totalDeductPoints = 0;
   }
   public String getName()
   {
       return name;
   }
   public void deductPoints(int num)
   {
      
       totalDeductPoints = totalDeductPoints + num;
   }
   @Override
   public double getPercent() {
      
       percent = startingScorePoints - totalDeductPoints;
       return percent;
   }
   @Override
   public boolean isPassing() {
       if(totalDeductPoints > 15)
       {
           return false;
       }
       else
       {
           return true;
       }
   }
  
}

-------------------------------------------------------------------------------------------------------------------------------------------------

package my_chegg_package;

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");
                              
           }
      
  
}

--------------------------------------------------------------------------------------------------------------------------------------------------

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