java - I need of assistance with array assigning user inputs to an array, and do-while loop repeat -
i'm having few problems code, on goal of program.
one of professors hears of emerging programming expertise , asks write single program can used them grading. professor gives 3 50-point exams , single 100-point final exam. program prompt user student’s name, entered firstname lastname (i.e. bob smith), student’s 3-exam scores , 1-final exam score (all whole numbers). class size varies semester semester, 100 limit (declare constant).
read in information students before doing calculations or displaying output. verify 3 exam scores between 0-50 points , final between 0-100 entered. declared minimums , maximums constant can updated, needed. if invalid, display error message , allow user re-enter invalid score. once student info read in, display each student’s name in format lastname, firstname (all uppercase), student’s exam percentage (total of exams plus final / total possible) 1 decimal , student’s final grade.
this have:
import java.util.*; import java.text.*; public class proj4 { public static void main(string[] args){ scanner s= new scanner(system.in); string input; string again = "y"; final int max_students = 100; final int min_exam = 0; final int max_exam = 50; final int min_final = 0; final int max_final = 100; string[] names = new string[max_students]; int [] exams = new int[max_students * 4]; int student = 1; { system.out.print("please enter name of student " + student + ": " ); (int k = 0; k < 1; k++) { names[k] = s.nextline().touppercase(); } ( int = 0; < 4; i++){ if(i==3){ system.out.print("please enter score final exam: "); exams[i] = s.nextint(); } else{ system.out.print("please enter score exam " + (i+1) + ": "); exams[i] = s.nextint(); if((exams[0]<min_exam||exams[0]>max_exam)||(exams[1]<min_exam||exams[1]>max_exam)||(exams[2]<min_exam||exams[2]>max_exam)){ system.out.println("invalid enter 0-50 only..."); system.out.print("please re-enter score: "); exams[i] = s.nextint(); } else if(exams[3]<min_final||exams[3]>max_final){ system.out.println("invalid enter 0-100 only..."); system.out.print("please re-enter score: "); exams[i] = s.nextint(); } } } system.out.print("do wish enter another? (y or n) "); again = s.next(); if(again!="y") student++; }while (again.equalsignorecase ("y")); system.out.println("***class results***"); system.out.println(names[1] + "," + names[0] + " " + "exam percentage: "+ ((exams[0]+exams[1]+exams[2]+exams[3])/(max_exam*3+max_final))); } } the problems have have are:
- figuring out how assign user entered test scores beyond first student, believe have set correct one, runs problem when move on second student.
for reason cannot figure out line
system.out.print("do wish enter another? (y or n) "); again = s.next();doesn't allow me enter anything, not y not n not anything, program ends there, doesn't make sense me because i've done before , has worked.
other that, if there other problems can see code pointing them out extremely helpful.
thank you
edit-
new problem having, after changing
if(!again.equalsignorecase("y")) student++; }while (again.equalsignorecase ("y")); it lets me type things in now, after type in y prints next line as
please enter name of student 1: please enter score exam 1:
i don't know why or need change fix it, suggestions?
`if(again!="y")` culprit here you should use equals() method check string equality.
if(!again.equals("y"))
Comments
Post a Comment