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

//..............................................................................

ID: 3547375 • Letter: #

Question

//...............................................................................................................................................................................

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

Internally we're using helpers to get/set private and private static variables as well as invoke private and private static methods. The following patterns will let you do pretty much anything related to the private methods and fields. Of course you can't change private static final variables through reflection.

And for fields:

Notes:
* targetClass.getDeclaredMethod(methodName, argClasses) lets you look into private methods. The same thing applies for getDeclaredField.
* The setAccessible(true) is required to play around with privates.