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

Can someone help me fill in the code for these test scenarios for the StudentCol

ID: 3724377 • Letter: C

Question

Can someone help me fill in the code for these test scenarios for the StudentCollection Class. The JUnit test should show all of these test cases passing. Code in Java.

//StudentCollectionTest

import org.junit.After;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

public class StudentCollectionTest
{
public StudentCollectionTest()
{
}

@BeforeClass
public static void setUpClass()
{
}

@AfterClass
public static void tearDownClass()
{
}

@Before
public void setUp()
{
}

@After
public void tearDown()
{
}

@Test
public void testGetCapacity()
{
System.out.println("getCapacity");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
int expResult = 0;
int result = instance.getCapacity();
assertEquals(expResult, result);
fail("The test case is a prototype.");
}

@Test
public void testReset()
{
System.out.println("reset");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
instance.reset();
fail("The test case is a prototype.");
}

@Test
public void testIsFull()
{
System.out.println("isFull");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
boolean expResult = false;
boolean result = instance.isFull();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

@Test
public void testIsEmpty()
{
System.out.println("isEmpty");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
boolean expResult = false;
boolean result = instance.isEmpty();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

@Test
public void testGetStudentCount()
{
System.out.println("getStudentCount");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
int expResult = 0;
int result = instance.getStudentCount();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

@Test
public void testGetSpacesRemaining()
{
System.out.println("getSpacesRemaining");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
int expResult = 0;
int result = instance.getSpacesRemaining();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

@Test
public void testAddStudent()
{
System.out.println("addStudent");
studentspec.StudentSpec aStudent = null;
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
instance.addStudent(aStudent);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

@Test
public void testRetrieveStudentBySID()
{
System.out.println("retrieveStudentBySID");
java.lang.String sidKey = "";
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
studentspec.StudentSpec expResult = null;
studentspec.StudentSpec result = instance.retrieveStudentBySID(sidKey);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

@Test
public void testRemoveStudentBySID()
{
System.out.println("removeStudentBySID");
java.lang.String sidKey = "";
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
studentspec.StudentSpec expResult = null;
studentspec.StudentSpec result = instance.removeStudentBySID(sidKey);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

@Test
public void testToString()
{
System.out.println("toString");
StudentCollectionSpec instance = StudentCollection.createStudentCollection();
String expResult = "";
String result = instance.toString();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

@Test

public void testCreateIterator()
{
System.out.println("createIterator");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
java.util.Iterator expResult = null;
java.util.Iterator result = instance.createIterator();
assertEquals(expResult, result);
   fail("The test case is a prototype.");
}
}

================================================================================

//StudentCollection.java

package studentcollection;


public class StudentCollection implements StudentCollectionSpec
{
public StudentCollection(int capacity)
{
  
}

public StudentCollection()
{

}

@Override
public int getCapacity()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void reset()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public boolean isFull()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public boolean isEmpty()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public int getStudentCount()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public int getSpacesRemaining()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void addStudent( studentspec.StudentSpec aStudent ) throws studentcollection.StudentCollectionSpec.StudentCollectionException
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public studentspec.StudentSpec retrieveStudentBySID( java.lang.String sidKey )
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public studentspec.StudentSpec removeStudentBySID( java.lang.String sidKey )
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public java.util.Iterator<studentspec.StudentSpec> createIterator()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

}

===================================================================================

package studentcollection;

//StudentCollectionSpec.java

import java.io.Serializable;
import studentspec.StudentSpec;

import java.util.Iterator;


public interface StudentCollectionSpec extends Serializable
{
  
public int getCapacity();

public void reset();


public boolean isFull();

public boolean isEmpty();

public int getStudentCount();

public int getSpacesRemaining();


public void addStudent(StudentSpec aStudent) throws StudentCollectionException;

  
public StudentSpec retrieveStudentBySID(String sidKey);

  
public StudentSpec removeStudentBySID(String sidKey);

  
@Override
public String toString();

  
public Iterator<StudentSpec> createIterator();

public class StudentCollectionException extends RuntimeException
{
private static final long serialVersionUID = 8157997298448463708L;

/* constructor that accepts a direct reason why the exception is to be created. */
public StudentCollectionException(String cause)
{
super(cause);
}

public StudentCollectionException(String cause, Throwable causalException)
{
super(cause, causalException);
}

}

}

===============================================================================

//Student.java

package studentspec;


public class Student implements StudentSpec
{


public Student( String theSID, String theFirstName, String theMiddleInitial, String theLastName,
String theMajor, double theTotalDegreeCredits, double theTotalQualityPoints )
{

}

@Override
public java.lang.String getFirstName()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public Student( String theSID, String theFirstName, String theMiddleInitial,
String theLastName, String theMajor )
{

}

@Override
public java.lang.String getMiddleInitial()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public java.lang.String getLastName()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public java.lang.String getSID()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public double getTotalDegreeCredits()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public double getTotalQualityPoints()
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public studentspec.StudentSpec clone() throws java.lang.CloneNotSupportedException
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void setFirstName( java.lang.String theFirstName ) throws studentspec.StudentSpec.StudentSpecException
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void setMiddleInitial( java.lang.String theMiddleInitial )
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void setLastName( java.lang.String theLastName ) throws studentspec.StudentSpec.StudentSpecException
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void setSID( java.lang.String theSID ) throws studentspec.StudentSpec.StudentSpecException
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void setGPAIngredients( double theTotalDegreeCredits, double theTotalQualityPoints )
throws studentspec.StudentSpec.StudentSpecException
{
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

}

===============================================================================

//StudentSpec.java

package studentspec;


import java.io.Serializable;

public interface StudentSpec extends Cloneable, Serializable
{
public static final double MAX_GPA = 4.0;
public static final double MIN_GPA = 0.0;
public static final double DEFAULT_TOTAL_DEGREE_CREDITS = 0.0;
public static final double DEFAULT_TOTAL_QUALITY_POINTS = 0.0;

public String getFirstName();

public String getMiddleInitial();

  
public String getLastName();

  
public String getSID();


public double getTotalDegreeCredits();


public double getTotalQualityPoints();

  
@Override
public String toString();

public StudentSpec clone() throws CloneNotSupportedException;

  
public void setFirstName(String theFirstName) throws StudentSpecException;


public void setMiddleInitial(String theMiddleInitial);


public void setLastName(String theLastName) throws StudentSpecException;

  
public void setSID(String theSID) throws StudentSpecException;

public void setGPAIngredients(double theTotalDegreeCredits,
double theTotalQualityPoints) throws StudentSpecException;


public class StudentSpecException extends RuntimeException implements Serializable
{
private static final long serialVersionUID = 5790641133393241596L;
  
public StudentSpecException(String cause)
{
super(cause);
}

public StudentSpecException(String cause, Exception causalException)
{
super(cause, causalException);
}

}

}

==============================================================================

Explanation / Answer

package studentcollection;

import studentspec.StudentSpec;

public class Student implements StudentSpec
{
   String theSID,
   theFirstName,
   theMiddleInitial,
   theLastName,
   theMajor;
   double theTotalDegreeCredits,
   theTotalQualityPoints;

public Student( String theSID, String theFirstName, String theMiddleInitial, String theLastName,
String theMajor, double theTotalDegreeCredits, double theTotalQualityPoints )
{
this.theSID=theSID;
this.theFirstName=theFirstName;
this.theMiddleInitial=theMiddleInitial;
this.theLastName=theLastName;
this.theMajor=theMajor;
this.theTotalDegreeCredits=theTotalDegreeCredits;
this.theTotalQualityPoints=theTotalQualityPoints;
}

@Override
public java.lang.String getFirstName()
{
   return theFirstName;
}
public Student( String theSID, String theFirstName, String theMiddleInitial,
String theLastName, String theMajor )
{
   this.theSID=theSID;
   this.theFirstName=theFirstName;
   this.theMiddleInitial=theMiddleInitial;
   this.theLastName=theLastName;
   this.theMajor=theMajor;
}

@Override
public java.lang.String getMiddleInitial()
{
   return theMiddleInitial;
}

@Override
public java.lang.String getLastName()
{
   return theLastName;
}

@Override
public java.lang.String getSID()
{
   return theSID;
}

@Override
public double getTotalDegreeCredits()
{
   return theTotalDegreeCredits;
}

@Override
public double getTotalQualityPoints()
{
   return theTotalQualityPoints;
}

@Override
public StudentSpec clone() throws java.lang.CloneNotSupportedException
{
   return this.clone();
}

@Override
public void setFirstName( java.lang.String theFirstName ) throws studentspec.StudentSpecException
{
   this.theFirstName=theFirstName;
  
}

@Override
public void setMiddleInitial( java.lang.String theMiddleInitial )
{
   this.theMiddleInitial=theMiddleInitial;
}

@Override
public void setLastName( java.lang.String theLastName ) throws studentspec.StudentSpecException
{
   this.theLastName=theLastName;
}

@Override
public void setSID( java.lang.String theSID ) throws studentspec.StudentSpecException
{
   this.theSID=theSID;
}

@Override
public void setGPAIngredients( double theTotalDegreeCredits, double theTotalQualityPoints )
throws studentspec.StudentSpecException
{
   setGPAIngredients(theTotalDegreeCredits, theTotalQualityPoints);
}

}

package studentcollection;

import java.util.ArrayList;
import java.util.List;

import studentspec.StudentSpec;

public class StudentCollection implements StudentCollectionSpec
{
/**
   *
   */
   private static final long serialVersionUID = 1L;
   private int capcity;
   private List<StudentSpec> students;

public StudentCollection(int capacity)
{
this.capcity=capacity;
}

public StudentCollection()
{
   students=new ArrayList<>();
}

@Override
public int getCapacity()
{
   return capcity;
}

@Override
public void reset()
{
   students=null;
   capcity=0;
}

@Override
public boolean isFull()
{
   return students.size()>capcity;
}

@Override
public boolean isEmpty()
{
   return students.isEmpty();
}

@Override
public int getStudentCount()
{
   return students.size();
}

@Override
public int getSpacesRemaining()
{
   return capcity-students.size();
}

@Override
public void addStudent( studentspec.StudentSpec aStudent ) throws studentcollection.StudentCollectionSpec.StudentCollectionException
{
   students.add(aStudent);
}

@Override
public studentspec.StudentSpec retrieveStudentBySID( java.lang.String sidKey )
{
   for (StudentSpec student : students) {
       if(student.getSID().equalsIgnoreCase(sidKey));
       {
           return student;
       }
   }
   return null;
}

@Override
public studentspec.StudentSpec removeStudentBySID( java.lang.String sidKey )
{
   for (StudentSpec student : students) {
       if(student.getSID().equalsIgnoreCase(sidKey));
       {
           students.remove(student);
           return student;
          
       }
   }
   return null;
}

@Override
public java.util.Iterator<studentspec.StudentSpec> createIterator()
{
   return students.iterator();
}

public static StudentCollectionSpec createStudentCollection() {
   return new StudentCollection();
}

}

package studentcollection;

import java.io.Serializable;
import studentspec.StudentSpec;

import java.util.Iterator;


public interface StudentCollectionSpec extends Serializable
{

public int getCapacity();

public void reset();


public boolean isFull();

public boolean isEmpty();

public int getStudentCount();

public int getSpacesRemaining();


public void addStudent(StudentSpec aStudent) throws StudentCollectionException;


public StudentSpec retrieveStudentBySID(String sidKey);


public StudentSpec removeStudentBySID(String sidKey);


@Override
public String toString();


public Iterator<StudentSpec> createIterator();

public class StudentCollectionException extends RuntimeException
{
private static final long serialVersionUID = 8157997298448463708L;

/* constructor that accepts a direct reason why the exception is to be created. */
public StudentCollectionException(String cause)
{
super(cause);
}

public StudentCollectionException(String cause, Throwable causalException)
{
super(cause, causalException);
}

}

}

package studentcollection;

import static org.junit.Assert.assertEquals;

//StudentCollectionTest

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class StudentCollectionTest
{
public StudentCollectionTest()
{
}

@BeforeClass
public static void setUpClass()
{
}

@AfterClass
public static void tearDownClass()
{
}

@Before
public void setUp()
{
}

@After
public void tearDown()
{
}

@Test
public void testGetCapacity()
{
System.out.println("getCapacity");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
int expResult = 0;
int result = instance.getCapacity();
assertEquals(expResult, result);
}

@Test
public void testReset()
{
System.out.println("reset");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
instance.reset();
}

@Test
public void testIsFull()
{
System.out.println("isFull");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
boolean expResult = false;
boolean result = instance.isFull();
assertEquals(expResult, result);

}

@Test
public void testIsEmpty()
{
System.out.println("isEmpty");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
boolean expResult = false;
boolean result = instance.isEmpty();
assertEquals(expResult, result);
}

@Test
public void testGetStudentCount()
{
System.out.println("getStudentCount");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
int expResult = 0;
int result = instance.getStudentCount();
assertEquals(expResult, result);
}

@Test
public void testGetSpacesRemaining()
{
System.out.println("getSpacesRemaining");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
int expResult = 0;
int result = instance.getSpacesRemaining();
assertEquals(expResult, result);
}

@Test
public void testAddStudent()
{
System.out.println("addStudent");
studentspec.StudentSpec aStudent = null;
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
instance.addStudent(aStudent);
}

@Test
public void testRetrieveStudentBySID()
{
System.out.println("retrieveStudentBySID");
java.lang.String sidKey = "";
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
studentspec.StudentSpec expResult = null;
studentspec.StudentSpec result = instance.retrieveStudentBySID(sidKey);
assertEquals(expResult, result);
}

@Test
public void testRemoveStudentBySID()
{
System.out.println("removeStudentBySID");
java.lang.String sidKey = "";
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
studentspec.StudentSpec expResult = null;
studentspec.StudentSpec result = instance.removeStudentBySID(sidKey);
assertEquals(expResult, result);
}

@Test
public void testToString()
{
      System.out.println("toString");
      StudentCollectionSpec instance = StudentCollection.createStudentCollection();
      String expResult = "";
      String result = instance.toString();
      assertEquals(expResult, result);
}

@Test

public void testCreateIterator()
{
System.out.println("createIterator");
studentcollection.StudentCollection instance = new studentcollection.StudentCollection();
java.util.Iterator expResult = null;
java.util.Iterator result = instance.createIterator();
assertEquals(expResult, result);
}
}

package studentspec;

import java.io.Serializable;

public interface StudentSpec extends Cloneable, Serializable
{
public static final double MAX_GPA = 4.0;
public static final double MIN_GPA = 0.0;
public static final double DEFAULT_TOTAL_DEGREE_CREDITS = 0.0;
public static final double DEFAULT_TOTAL_QUALITY_POINTS = 0.0;

public String getFirstName();

public String getMiddleInitial();


public String getLastName();


public String getSID();


public double getTotalDegreeCredits();


public double getTotalQualityPoints();


@Override
public String toString();

public StudentSpec clone() throws CloneNotSupportedException;


public void setFirstName(String theFirstName) throws StudentSpecException;


public void setMiddleInitial(String theMiddleInitial);


public void setLastName(String theLastName) throws StudentSpecException;


public void setSID(String theSID) throws StudentSpecException;

public void setGPAIngredients(double theTotalDegreeCredits,
double theTotalQualityPoints) throws StudentSpecException;
}

package studentspec;

import java.io.Serializable;

public class StudentSpecException extends RuntimeException implements Serializable
{
private static final long serialVersionUID = 5790641133393241596L;

public StudentSpecException(String cause)
{
super(cause);
}

public StudentSpecException(String cause, Exception causalException)
{
super(cause, causalException);
}

}

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