/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package code31jan19ifelsebinary; import java.util.Scanner; /** * * @author jcmtiernan */ public class Code31Jan19ifelsebinary { /** * @param args the command line arguments */ public static void main(String[] args) { // Choices /* Class has 3 tests worth 60% of final grade Final 40% Do a research project 40% OR Take two more tests for 40% of grade OR Write 8 lab reports for 40% of grade Assumption: all grades are out of 100 Algorithm for final grade: Average the 3 tests and mult by percentage (60) Find out how they are doing the final 40% if student chose the research project multiply project grade by 40% and save as final40Pct else if student chose two tests Average the 2 tests and mult by percentage (40) and save as final40Pct else if student chose 8 reports Average 8 reports and mult by percentage (40) and save as final40Pct // Final grade is 3 test value plus whichever they chose Final grade is 3 test value plus final40Pct */ Scanner userIn = new Scanner(System.in); double test1=0, test2=0, test3=0; System.out.println("Please enter the three test grades separated by spaces: "); test1 = userIn.nextDouble(); test2 = userIn.nextDouble(); test3 = userIn.nextDouble(); userIn.nextLine(); // Class has 3 tests worth 60% of final grade double test60Pct = (test1 + test2+ test3)/3 * .6; System.out.println("The test average is "+test60Pct+" out of 60%"); // Find out how they are doing the final 40% System.out.println("\nWhich choice did you make for the final 40% of your grade?"); System.out.println("A. Reseach project"); System.out.println("B. Two additional tests"); System.out.println("C. Eight reports"); System.out.println("Please enter A, B, or C for your choice:"); char response = 'Z'; //String resp = ""; //resp = userIn.next(); //response = resp.charAt(0); response = userIn.nextLine().charAt(0); System.out.print("You entered choice: "+response+"\n"); // we are NOT going to do input validation (but later...) // at this point response should have 'A' or 'B' or 'C' /* if student chose the research project multiply project grade by 40% and save as final40Pct else if student chose two tests Average the 2 tests and mult by percentage (40) and save as final40Pct else if student chose 8 reports Average 8 reports and mult by percentage (40) and save as final40Pct */ double final40Pct = 0; int countNotA = 0; if (response == 'A') // if (test for project choice) { // true - statement to execute double project; System.out.println("Enter the project grade 0.0 - 100.0 "); project = userIn.nextDouble(); final40Pct = project * .4; //final40Pct = userIn.nextDouble() * .4; System.out.println("The project grade was "+project); } else { System.out.println("You did not enter 'A' "); //countNotA = countNotA + 1; // increment //countNotA += 1; countNotA++; } if (response == 'B') // test is always executed { double test4=0, test5=0; System.out.println("Please enter the final two test grades separated by spaces: "); test4 = userIn.nextDouble(); test5 = userIn.nextDouble(); final40Pct = (test4 + test5)/2 * .4; System.out.println("The final test average is "+final40Pct+" out of 40%"); } else { System.out.println("You did not enter 'B' "); } if (response == 'C') // test is always executed { double rpt1=0, rpt2=0, rpt3=0, rpt4=0, rpt5=0, rpt6=0, rpt7=0, rpt8=0 ; System.out.println("Please enter the eight report grades separated by spaces: "); rpt1 = userIn.nextDouble(); rpt2 = userIn.nextDouble(); rpt3 = userIn.nextDouble(); rpt4 = userIn.nextDouble(); rpt5 = userIn.nextDouble(); rpt6 = userIn.nextDouble(); rpt7 = userIn.nextDouble(); rpt8 = userIn.nextDouble(); final40Pct = (rpt1 + rpt2 + rpt3 + rpt4 + rpt5 + rpt6 + rpt7 + rpt8)/8 * .4; System.out.println("The final report average is "+final40Pct+" out of 40%"); } else { System.out.println("You did not enter 'C' "); } // they did not enter A, B or C /* { System.out.println("Your choice was not valid"); final40Pct = 0; } */ System.out.println("After user input final 40% is "+final40Pct); double courseGrade = test60Pct + final40Pct; System.out.println("\nYour final course grade is "+courseGrade); } }