2014-11-21 2 views
0

우리는 GradeBook이라는 프로그램을 작성하고 있으며 사용자가 이름과 점수 항목 등의 학생 데이터를 입력 할 수 있습니다. GradeBook은 각 학생에 대한 옵션 계산 학점을 제공하고 학급 분포를 계획합니다. 사용자는 언제든지 돌아가서 더 많은 학생 데이터를 추가 할 수 있습니다. 지원하는 최대 학생 수는 200 명이며 카테고리의 성적 항목의 최대 수는 10입니다. 예를 들어, 퀴즈 10 개, 시험 10 개, 숙제 10 개까지만 지원할 수 있습니다.배열을 사용한 그레이드 계산기

데이터 유입의 예는이 같은 것입니다 :

조 W. 스미스 : E100 E95 E87 Q10 Q10을 Q8의 H10의 H10의 H10

마이클 브라운 : Q10 Q10의 H7 H10의 H9의 H10 E80

학생들의 성적과 통계를 표시하려면 System.out.printf를 사용해야합니다.

다음은 최종 산출물의 다른 예입니다. 이 단정하고 깨끗하게 보이지만 그 작업을 수행하는 방법에 대한 확실 해요 그래서

Name  Exam Exam Exam Quiz Quiz Quiz HWork HWork HWork Grade 

Danny Devito 100.0 80.0 90.0 10.0 10.0 0.0 10.0 5.0 10.0 84.0 

Joe Smith 85.0 90.0 100.0 10.0 10.0 5.0 0.0 10.0 5.0  81.7 

Will Smith 60.0 100.0 90.0 10.0 10.0 8.0 10.0 0.0 10.0 82.0 

마지막 예제

은 소수에 의해 더 나은 줄 지어 alligned 할 예정이다.

import java.util.Scanner; 

공용 클래스 GradeCalcWithArrays {/ * * 로건 웨 그너는 목적은 * 입력 등급 */ 공공 정적 무효 메인 (문자열 []에 args) {

Scanner s = new Scanner(System.in); 

    boolean done = false; 
    boolean quit = false; 
    int choice = 0; 

    int studentcounter = 0; 

    int[] examstats = new int[3]; /* 
           * Array created to store the information 
           * entered for exams 
           */ 
    int[] quizstats = new int[3]; /* 
           * Array created to store the information 
           * entered for quizzes 
           */ 
    int[] homeworkstats = new int[3]; /* 
            * Array created to store the 
            * information entered for homework 
            */ 

    String[] studentnames = new String[200]; /* 
              * Array created to store the 
              * student name information 
              * entered 
              */ 

    System.out.println("Welcome to GradeBook!"); 
    System.out.println("Please provide grade item details"); 

    System.out.print("Exams (number, points, weight):"); 

    examstats[0] = s.nextInt(); // inputs exam number 
    examstats[1] = s.nextInt(); // inputs exam points 
    examstats[2] = s.nextInt(); // inputs exam weight 

    System.out.print("Quizzes  (number, points, weight):"); 

    quizstats[0] = s.nextInt(); // inputs quiz number 
    quizstats[1] = s.nextInt(); // inputs quiz points 
    quizstats[2] = s.nextInt(); // inputs quiz weight 

    System.out.print("Homework (number, points, weight):"); 

    homeworkstats[0] = s.nextInt(); // inputs homework number 
    homeworkstats[1] = s.nextInt(); // inputs homework points 
    homeworkstats[2] = s.nextInt(); // inputs homework weight 

    System.out.println("--------------------"); 

    do { 
     System.out.println("What would you like to do?"); 
     System.out.println(" 1 Add student data"); 
     System.out.println(" 2 Display student grades & statistics"); 
     System.out.println(" 3 Plot grade distribution"); 
     System.out.println(" 4 Quit"); 
     System.out.print("Your choice:"); 
     choice = s.nextInt(); /* 
          * Choice will determine what the next course of 
          * action will be with the program 
          */ 

     if (choice == 1) { 
      System.out.println("Enter student data:"); 
      for (int i = 0; i <= 200; i++) { 
       studentcounter = studentcounter + 1; 
       System.out.print("Data>"); 
       studentnames[i] = s.nextLine(); 

       if (studentnames[i].equals("done")) { 
        break; 
       } 
      } 
     } 

     if (choice == 2) { 

     } 

     if (choice == 3) { 

     } 

     if (choice == 4) { 
      quit = true; 
      System.out.println("Good bye!"); 
     } 

    } while (quit == false); 

} 

} 

가장 큰를 계산하는 것이다 내가 붙어있는 부분은 데이터를 입력하고 문자열과 배열에 넣는 것뿐입니다. e100 q100 h100을 사용하여 입력 한 데이터를 가져 오는 방법을 잘 모르겠습니다. 나는 정말로 이것에 대한 도움을 정말로 정말로 바랄 것입니다. 선배 들께 감사드립니다.

답변

0

실제로 혼동스러워하는 것에 대한 질문을 찾으십시오. 보통 이것은 당신에게 당신이해야 할 일을 알아 내게합니다.

exam, quizhomework 문자열을 어떤 순서가 아니 어서 3 개의 별도 배열로 분리하는 것이 확실하지 않은 것처럼 보입니다. 글쎄, 그들을 구분하기 위해서는 차이점이 있어야합니다. 세 가지 유형의 문자열의 차이점은 무엇입니까?

모든 3 가지 유형의 문자열 입력은 'e', ​​'q'또는 'h'와 같이 0에서 100 사이의 숫자를 문자에 붙일 수 있습니다. 따라서 유일한 차이점은 각 문자열의 첫 번째 문자입니다. 따라서 다양한 문자열을 모두 별도의 배열로 분리하려면 첫 번째 문자가 무엇인지 확인한 다음 이에 따라 해당 배열에 배치하십시오.

이제 마침내 코드를 작성해야합니다. 첫 문자를 기준으로 프로그래밍 방식으로 문자열을 분리하는 방법은 무엇입니까?

글쎄, 당신은 if 진술을 가지고 있고 나는 당신이 어떻게 문자열의 첫 번째 문자를 얻는 지 알 수있을 것이라고 확신합니다.

는 (의사 일명) 단어에서 공개 :

String s; 
Char c; 

c = //get the first letter of string 's'. Figure this out with a simple google search. 

if (c == 'e') 
{ 
    //Add the string after the first character in string s to the Exam array 
    //NOTE: You have int arrays, so you will need to convert the string to an int 
    //  before adding it to the array. 
} 
else if (c == 'q') 
{ 
    //Same as above with Quiz array 
} 
else if ... 
{ 
    //... you should be able to finish this! 
} 

당신은 당신의 프로젝트를 시작한다이.나머지 과제에 대해 상술 한 생각 프로세스를 에뮬레이트하려고하면 초급 수준에서 발생하는 모든 문제가 이전에 해결되었음을 빨리 알 수 있습니다. 프로그래밍과 관련하여 문제가 무엇인지 구체적으로 파악해야합니다.

+0

도움 주셔서 감사합니다. 그건 분명히 내 질문의 90 %였다. s.firstLetter 일을하는 대신 당신이 의미하는 바를 알고 있다고 생각합니다. 당신은 내가 e를 골라 내기 위해 분할을 사용해야한다는 것을 말하고 있습니까? 그렇다면 올바른 배열에 다른 점수를 입력 할 수 있습니까? 또는 하위 문자열을 사용하여 전자를 찾은 다음 올바른 배열의 성적을 입력해야합니까? – Daniel

+0

@ 다니엘 당신에게 가장 이해가되는 것은 무엇이든합니다. 당신은 여러 가지 방법으로 그것을 할 수 있습니다. 나는 당신에게 정확히 어떻게하는지 말하고 싶지 않지만 위에 게시 한 코드를 읽으면 그것을 분석하고 내 사고 과정과 의도를 파악할 수 있습니다 (주로 'if'블록을 통해). – Matthew

+0

주어진 예제는 'Joe Smith : e100 e80 e90 q10 q10 q0 h10 h5 h10'입니다. J가 시작의 첫 문자이고 e, q 및 h가 두 개 이상 있습니다. 이 문제에 대해 어떻게 설명했는지는 문자 만 정확합니다. 나는 3 e를 찾거나 어떻게 될지에 관해서 혼란 스럽다. 그리고 배열에 모든 값을 가져온다. – Daniel