I need a program that will do few unit testing functions to test the class below
ID: 3547442 • Letter: I
Question
I need a program that will do few unit testing functions to test the class below maybe you use junit or any other means ..................the class is below
..............................................................................................................................................................................
import java.util.*;
public class Majors
{
public static void main(String[] args)
{
@SuppressWarnings("resource")
Scanner keyboard = new Scanner(System.in);
int majorNum, //Major department
departNum, // class department
indexW, // indexOf('W'), ('S') and ('H')
indexS,
indexH;
boolean necessary=false; // necessary for output
String designators, // department designators
courseNum, // course number,
departString; // substring including first 3 digits of course num
char courseDivision; // upper/lower division classifier
double units; // number of units
System.out.println("Enter major department number: ");
majorNum = keyboard.nextInt();
// get course data
System.out.println("Enter course data (dpt.num units QXZABR): ");
courseNum = keyboard.next(); //course number input ###.### format
units = keyboard.nextDouble(); //number of units
designators = keyboard.nextLine(); //academic designators
//5th character of courseData string (upper/lower level classifier)
courseDivision = courseNum.charAt(4);
//substring of courseData used to determine the department of the class being taken
departString = courseNum.substring (0,3);
//department number turned from string to integer
departNum = Integer.parseInt(departString);
indexH = designators.toUpperCase().indexOf('H'); //search for 'H' in designators
indexW = designators.toUpperCase().indexOf('W'); //search for 'W' in designators
indexS = designators.toUpperCase().indexOf('S'); //search for 'S' in designators
if (departNum == 110 | departNum == 550) // if class department is 110 or 550...
{
System.out.println("This course will count towards your math requirement."); //the class counts for math requirement
necessary = true; //if any of these apply, necessary becomes true
}
if (indexW != -1 && units >= 3) //if there is a W in the designators and the class is at least 3 units...
{
System.out.println("This course will count towards your writing requirement."); //the class counts for writing requirement
necessary = true;
}
if ((indexH != -1 || indexS != -1) && units >= 3)// if there is a H or S designator and the class is at least 3 units..
{
System.out.println ("This course will count towards your High School requirement."); // the class counts for High School requirement
necessary = true;
}
if (majorNum == departNum)// if the class is in the student's major...
{
necessary = true;
if (courseDivision < '3') // and the class number is < 300
System.out.println("This course will count towards your lower division major requirement."); // the class satisfies a lower division major requirement.
else
System.out.println("This course will count towards your upper division major requirement."); // the class satisfies an upper division major requirement.
}
if (!necessary) // if necessary is not true
System.out.println("This course will count as elective credit only.");
}
}
Explanation / Answer
// import statements and package declarations public class ClassToTest { private int decrement(int toDecrement) { toDecrement--; return toDecrement; } // constructor and rest of class public static class StaticInnerTest extends TestCase { public StaticInnerTest(){ super(); } public void testDecrement(){ int number = 10; ClassToTest toTest= new ClassToTest(); int decremented = toTest.decrement(number); assertEquals(9, decremented); } public static void main(String[] args) { junit.textui.TestRunner.run(StaticInnerTest.class); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.