java - my program doesn't run completely -


for reason, program stops when reaches part asks user if know it's exam 1 score. need user able enter yes or no. why program stop? need work properly. have if-else statements. able enter percentage weights, program do. more must done. code extends far beyond entering percentage weights. please me.

import java.util.scanner; public class gradecalculation {      public static void main(string[] args) {         // todo auto-generated method stub          scanner grade = new scanner (system.in);          // new scanner must created. scanner essential program performing properly.           double = 90-100;          double b = 80-89;          double c = 70-79;          double d = 60-69;          double f = 0-59;         string lettergrade;          string yes;          string no;         double exam1, exam2, finalexam, labs, projects, attendance, quizzes;         double exam1grade, exam2grade, finalexamgrade, labaverage, projectsaverage, attendanceaverage, quizzesaverage;         double knownweight;         double percentageweights;          // always, variables must declared @ beginning of program.            system.out.print(                 "grading scale:\n"+                 "a = 90-100 \n"+                 "b = 80-89 \n"+                  "c = 70-79 \n"+                  "d = 60-69 \n"+                 "f = 00-59 \n");          system.out.println("what letter grade want achieve in course?");         lettergrade = grade.next();          // user type letter grade wants in part.           system.out.println("\nenter percentage weights: \t");          string input = grade.nextline();          // string above needed when user enters exam grades , averages.           system.out.print("\n\nexam 1: \t");          exam1 = grade.nextshort();         system.out.print("\nexam 2: \t");          exam2 = grade.nextshort();         system.out.print("\nfinal exam: \t");         finalexam = grade.nextshort();         system.out.print("\nlabs: \t");         labs = grade.nextshort();         system.out.print("\nprojects: \t");         projects = grade.nextshort();         system.out.print("\nattendance: \t");         attendance = grade.nextshort();         system.out.print("\nquizzes: \t");         quizzes = grade.nextshort();          percentageweights = (int)(exam1 + exam2 + finalexam + labs + projects + attendance + quizzes);          // equation above provide sum of percentage weights. since variables in equation          // declared doubles, had put "int" before actual equation.            if (percentageweights > 100 || percentageweights < 100) {              system.out.println("\nweights not add 100. program exiting. have nice day!");             system.exit(0);         }         else {              system.out.println("\nenter scores out of 100: \t");         }          // part above important continue rest of program. if sum of percentage weights equals 100,          // program continue run. if sum greater or less 100, program terminate.           system.out.print("\ndo know exam 1 score?");         if (input.equalsignorecase("yes")) {             system.out.print("\nscore received on exam 1: ");              exam1grade = grade.nextdouble();         }         else{              exam1grade = 0;         }          system.out.print("\ndo know exam 2 score?");         if (input.equalsignorecase("yes")) {              system.out.print("\nscore received on exam 2: ");             exam2grade = grade.nextdouble();         }         else{              exam2grade = 0;         }         system.out.print("\ndo know final exam score?");         if (input.equalsignorecase("yes")){              system.out.print("\nscore received on final exam: ");             finalexamgrade = grade.nextdouble();         }         else{             finalexamgrade = 0;         }         system.out.print("\ndo know lab average?");         if (input.equalsignorecase("yes")){              system.out.print("\naverage lab grade: ");              labaverage = grade.nextdouble();         }         else{             labaverage = 0;         }         system.out.print("\ndo know project average?");         if (input.equalsignorecase("yes")){             system.out.print("\naverage project grade: ");              projectsaverage = grade.nextdouble();         }         else{             projectsaverage = 0;         }         system.out.print("\ndo know quiz average?");         if (input.equalsignorecase("yes")) {         system.out.print("\naverage quiz grade: ");             quizzesaverage = grade.nextdouble();         }         else{              quizzesaverage = 0;           }          system.out.print("\ndo know attendance average?");         if (input.equalsignorecase("yes")){          system.out.print("\naverage attendance grade: ");             attendanceaverage = grade.nextdouble();         }         else{             attendanceaverage = 0;               }          // user has finished answering questions. program automatically calculate data based on          // user typed program.           double currentgrade, avgtofinallettergrade, weightandgrade, finaloverallgrade;           // doubles above need declared in order equations below work properly.           weightandgrade = (int)((exam1 * exam1grade) + (exam2 * exam2grade) + (finalexam * finalexamgrade) + (labs * labaverage) + (projects * projectsaverage) + (quizzes * quizzesaverage) + (attendance * attendanceaverage));          currentgrade = (int)((weightandgrade) / (exam1 + exam2 + finalexam + labs + projects + quizzes + attendance ));          knownweight = (exam1 + exam2 + finalexam + labs + projects + quizzes + attendance);          if (grade.equals(a)){              finaloverallgrade = 90;         }         else if (grade.equals(b)){              finaloverallgrade = 80;         }         else if (grade.equals(c)){              finaloverallgrade = 70;         }         else if (grade.equals(d)){              finaloverallgrade = 60;         }         else              finaloverallgrade = f;           avgtofinallettergrade = (((100-finaloverallgrade) * (weightandgrade)) / (100 - knownweight));          // equations above 1 of last parts of program. these equations critical determine whether or not user received desired letter grade.          // if desired grade not reached, program give score user must consistently receive in order possibly reach desired letter grade.          if (finaloverallgrade >= 90){              system.out.print("congratulations! got in class! hooray!");         }         else if (finaloverallgrade >=80 && finaloverallgrade < 90){              system.out.print("good job. got b in class!");         }         else if (finaloverallgrade >=70 && finaloverallgrade < 80){              system.out.print("you got c in class.");         }         else if (finaloverallgrade >=60 && finaloverallgrade < 70){             system.out.print("you got d in class.");         }         else              system.out.print("i'm sorry, have failing grade in class. may gpa have mercy on soul.");         }  } 

there quite lot of things wrong code. doing double a=90-100; set equal -10;

however, current question:

you string input = grade.nextline(); never change input, , if input isn't "yes", skip getting grades each piece.

(you might want consult using scanner.nextline() other pitfalls using scanner.nextline() intermixed scanner.nextint or similar [in summary: if scanner.nextint, doesn't consume newline, scanner.nextline() newline , not next line after might expecting get])


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -