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

Write a CS102 class that stores student information and marks, and calculates a

ID: 669023 • Letter: W

Question

Write a CS102 class that stores student information and marks, and calculates a student's final mark. Your class must implement the attached Student interface.

interface Student
{
public void setName ( String name );
public String getName ();
public void setMark ( String category, int mark );
public float getFinal ();   
}


The 4 methods in Student are as follows:
setName() sets the name of the student.
getName() returns the name of the student.
setMark() sets one of 4 marks, depending on the category parameter, which is one of {"pracs", "practests", "tests", "exam"}.
getFinal() returns the final mark using the formula from the notes to students. All calculations are done with floats.


There is no test program. Instead a technique called unit testing will be used.
Unit testing is an automatic testing technique for individual modules of a large software system. Tests are defined and executed automatically to rapidly test and re-test a class during development without user intervention. This helps to scale up testing when a program gets very large. It also ensures the correctness of each individual class within the system.
JUnit is one of the most popular unit testing frameworks for Java. The advantage of a framework (rather than writing small programs to test each class) is that there is a standard API, common understanding of the testing approach among Java programmers and integrated support in many IDEs.

Write JUnit tests for your CS102 class in a class called CS102Test, stored in the file CS102Test.java. These 4 tests must be included.
1. A test that getName() returns the value set using setName().
2. A test that, if all marks are 0, the final mark is 0.
3. A test that, if all marks are 100, the final mark is 100.
4. A test that the final mark is correctly calculated for all marks being between 0 and 100.

JUnit is used.In order to compile the JUnit test class from the command-line, a command such as:
javac -cp junit-4.12.jar:hamcrest-core-1.3.jar:. CS102Test.java
And in order to execute the JUnit tests from the command-line, a command such as:
java -cp junit-4.12.jar:hamcrest-core-1.3.jar:. org.junit.runner.JUnitCore CS102Test

Complete this task and partial credit will be earned. Eclipse or Jgrasp can only be used.

Explanation / Answer

Student interface:

interface Student {
   public void setName(String name);
   public String getName();
   public void setMark(String category, int mark);
   public float getFinal();
}

//######################################################################################

Class CS102

public class CS102 implements Student {

   private String name;
   int pracs, tests, exam, practests;

   @Override
   public void setName(String name) {
       this.name = name;

   }

   @Override
   public String getName() {

       return this.name;
   }

   @Override
   public void setMark(String category, int mark) {
       switch (category) {
       case "pracs":
           pracs = mark;
           break;

       case "tests":
           tests = mark;
           break;

       case "exam":
           exam = mark;
           break;

       case "practests":
           practests = mark;
           break;

       default:
           System.out.println("Category not found!!");
       }

   }

   @Override
   public float getFinal() {
       float finalScore = (float) (0.15 *pracs+ 0.15 *tests+ 0.10 *practests+ 0.60 *exam);
       return finalScore;
   }

}

//###########################################################################################

Class CS102Test:

import static org.junit.Assert.*;
import org.junit.Test;

public class CS102Test {
   @Test
   public void testGetName() {
       CS102 student1 = new CS102();
       student1.setName("Alex");

       assertEquals("Alex", student1.getName());
   }

   @Test
   public void textMarksOne() {
       CS102 student1 = new CS102();
       student1.setMark("pracs", 0);
       student1.setMark("practests", 0);
       student1.setMark("tests", 0);
       student1.setMark("exam", 0);

       assertEquals(0, student1.getFinal(), 0);
   }

   @Test
   public void textMarksTwo() {
       CS102 student1 = new CS102();
       student1.setMark("pracs", 100);
       student1.setMark("practests", 100);
       student1.setMark("tests", 100);
       student1.setMark("exam", 100);

       assertEquals(100, student1.getFinal(), 0);
   }

   @Test
   public void textMarksThree() {
       CS102 student1 = new CS102();
       student1.setMark("pracs", 70);
       student1.setMark("practests", 90);
       student1.setMark("tests", 100);
       student1.setMark("exam", 0);

       assertEquals(34.5, student1.getFinal(), 0);
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote