Last active
August 29, 2015 13:57
-
-
Save TylerLH/9801693 to your computer and use it in GitHub Desktop.
Project1.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Project1 | |
{ | |
public static void main (String[] args) | |
{ | |
Scanner kb = new Scanner(System.in); | |
Boolean running = true; | |
double originalGrade = 0; | |
int userSelection = 0; | |
int pointSelection = 0; | |
double percentageSelection = 0; | |
double newGrade = 0; | |
double curvePts = 0; | |
originalGrade = askUser();//asks for original grade | |
while(running) { | |
userSelection = menuSelection();//displays menu selection and asks for selection | |
switch(userSelection)//processes the user's selections | |
{ | |
case 1://process for input of 1 | |
curvePts = 10; | |
newGrade = applyCurve(curvePts, originalGrade); | |
System.out.println("\n\n\n\tCurve applied: " + curvePts + " points"); | |
System.out.println("\n\tAdjusted grade: " + newGrade); | |
break; | |
case 2://process for input of 2 | |
curvePts = originalGrade * .10; | |
newGrade = applyCurve(curvePts, originalGrade); | |
System.out.println("\n\n\n\tCurve applied: " + curvePts + " points"); | |
System.out.println("\n\tAdjusted grade: " + newGrade); | |
break; | |
case 3://process for input of 3 | |
pointSelection = optionThree(); | |
curvePts = pointSelection; | |
newGrade = applyCurve(curvePts, originalGrade); | |
System.out.println("\n\n\n\tCurve applied: " + curvePts + " points"); | |
System.out.println("\n\tAdjusted grade: " + newGrade); | |
break; | |
case 4://process of input of 4 | |
percentageSelection = optionFour(); | |
curvePts = percentCalc(percentageSelection, originalGrade); | |
newGrade = applyCurve(curvePts, originalGrade); | |
System.out.println("\n\n\n\tCurve applied: " + curvePts + " points"); | |
System.out.println("\n\tAdjusted grade: " + newGrade); | |
break; | |
case 5://process of input of 5 (exit) | |
running = false; | |
System.exit(0); | |
break; | |
}//end switch | |
freezeScreen();//freezes screen and asks user to hit ENTER to continue | |
} | |
}//end main | |
public static Double askUser() | |
{ | |
Scanner kb = new Scanner(System.in); | |
double originalGrade = 0; | |
clearScreen(); | |
System.out.print("What is the original grade? "); | |
originalGrade = kb.nextDouble(); | |
while(originalGrade < 0 || originalGrade > 100)//input validation for grades entered below or above 100 | |
{ | |
System.out.print("\n\nError. Please enter a grade between 0 and 100."); | |
System.out.print("\n\n\nWhat is the original grade? "); | |
originalGrade = kb.nextDouble(); | |
}//end while | |
return originalGrade; | |
}//end askUser | |
public static int menuSelection() | |
{ | |
Scanner kb = new Scanner(System.in); | |
int userSelection = 0; | |
clearScreen(); | |
System.out.print("\n\n\tGrade Adjuster" | |
+ "\n\tby Haley Hughes" | |
+ "\n" | |
+ "\n******************************" | |
+ "\n" | |
+ "\n1. Curve by 10 points" | |
+ "\n2. Curve by 10 percent" | |
+ "\n3. Curve by a given number of points" | |
+ "\n4. Curve by a given percentage" | |
+ "\n5. Quit" | |
+ "\n\nEnter your selection: "); | |
userSelection = kb.nextInt(); | |
while (userSelection < 1 || userSelection > 5)//input validation for input less that 1 or more than 5 | |
{ | |
System.out.print("\n\nError. Please select 1 through 5.\n\n"); | |
System.out.print("\n\n\tGrade Adjuster" | |
+ "\n\tby Haley Hughes" | |
+ "\n" | |
+ "\n******************************" | |
+ "\n" | |
+ "\n1. Curve by 10 points" | |
+ "\n2. Curve by 10 percent" | |
+ "\n3. Curve by a given number of points" | |
+ "\n4. Curve by a given percentage" | |
+ "\n5. Quit" | |
+ "\n\nEnter your selection: "); | |
userSelection = kb.nextInt(); | |
}//end while | |
return userSelection; | |
}//end menuSelection | |
public static void freezeScreen() | |
{ | |
Scanner kb = new Scanner(System.in); | |
System.out.println("\n\npress ENTER to return to the Menu..."); | |
kb.nextLine();//catches enter key input | |
//menuSelection();//displays the menu | |
}//end freezeScreen | |
public static void clearScreen() | |
{ | |
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); | |
}//end clearScreen | |
public static int optionThree() | |
{ | |
Scanner kb = new Scanner(System.in); | |
int pointSelection = 0; | |
System.out.print("\n\n\nHow many points should be applied to curve the grade? "); | |
pointSelection = kb.nextInt(); | |
while (pointSelection < 0 || pointSelection > 25)//input validation for input less than 0 or more than 25 | |
{ | |
System.out.println("\n\nError. Please enter a number between 0 and 25."); | |
System.out.print("\n\nHow many points should be applied to curve the grade? "); | |
pointSelection = kb.nextInt(); | |
}//end while | |
return pointSelection; | |
}//end optionThree | |
public static double optionFour() | |
{ | |
Scanner kb = new Scanner(System.in); | |
double percentageSelection = 0; | |
System.out.print("\nEnter the percentage of the curve: " | |
+ "(ex. 10% would be entered as .10) "); | |
percentageSelection = kb.nextDouble(); | |
while (percentageSelection < .0 || percentageSelection > .50)//input validation for input less than .0 or more than .50 | |
{ | |
System.out.println("\n\nError. Please enter a percentage between .0 and .50."); | |
System.out.print("\n\nEnter the percentage of the curve: " | |
+ "(ex. 10% would be entered as .10) "); | |
percentageSelection = kb.nextDouble(); | |
}//end while | |
return percentageSelection; | |
}//end optionFour | |
public static double percentCalc(double percentageSelection, double originalGrade) | |
{ | |
double curvePts = 0; | |
curvePts = originalGrade * percentageSelection; | |
return curvePts; | |
}//end percentCalc | |
public static double applyCurve(double originalGrade, double curvePts) | |
{ | |
double newGrade = 0; | |
newGrade = originalGrade + curvePts; | |
while (newGrade > 100) | |
{ | |
newGrade = 100; | |
}//end while | |
return newGrade; | |
}//end applyCurve | |
}//end Project1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment