Student Records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • waldoruns
    New Member
    • Oct 2006
    • 4

    #1

    Student Records

    I need help too figure out how to get the numbers 8, 9, 76,99 comment out of the code so when i run the program, that the user can input their own numbers.









    public class StudentRecordDe mo {

    /**
    * StudentRecordDe mo main() is used to validate and verify
    * that all of the methods and data members of the class
    * do or contain what they are supposed.
    */
    public static void main(String[] args) {
    StudentRecord g1 = new StudentRecord() ;
    g1.set(8, 9, 76, 99);
    g1.writeOutput( );
    System.out.prin tln("StudentRec ordDemo done.");
    }

    public class StudentRecord {
    // data members:
    private int quiz1;
    private int quiz2;
    private int midterm;
    private int finalExam;
    private float finalGrade;
    private char letterGrade;


    // data methods:
    /**
    * StudentRecord.s et() allows for the direct unverified input of data
    * members of the class for use in testing and setting values.
    */
    public void set(int q1, int q2, int mt, int fE) {
    quiz1 = q1;
    quiz2 = q2;
    midterm = mt;
    finalExam = fE;
    finalGrade = computeFinalGra de();
    letterGrade = computeLetterGr ade();
    }

    public void writeOutput() {
    System.out.prin tln("Quiz 1 = " + quiz1);
    System.out.prin tln("Quiz 2 = " + quiz2);
    System.out.prin tln("Midterm Exam= " + midterm);
    System.out.prin tln("Final Exam = " + finalExam);
    System.out.prin tln("Final Grade = " + finalGrade + " or an ["
    + letterGrade + "]");
    }

    /**
    * StudentRecord.c omputeFinalGrad e() takes all test scores and provides the
    * final computed class grade.
    */
    private float computeFinalGra de() {
    double tempGrade = 0.125 * (quiz1 * 10); // first quiz part
    tempGrade += 0.125 * (quiz2 * 10); // second quiz part
    tempGrade += 0.25 * midterm; // midterm part
    tempGrade += 0.50 * finalExam; // final exam part
    return (float) tempGrade;
    }

    /**
    * StudentRecord.c omputeLetterGra de() provides correct letter grade for the
    * final grade provided.
    */
    private char computeLetterGr ade()
    {
    char tempGrade = '?';
    if (finalGrade >= 89.5)
    tempGrade = 'A';
    else if (finalGrade >= 79.5)
    tempGrade = 'B';
    else if (finalGrade >= 69.5)
    tempGrade = 'C';
    else if (finalGrade >= 59.5)
    tempGrade = 'D';
    else
    tempGrade = 'F';
    return tempGrade;
    }
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by waldoruns
    I need help too figure out how to get the numbers 8, 9, 76,99 comment out of the code so when i run the program, that the user can input their own numbers.









    public class StudentRecordDe mo {

    /**
    * StudentRecordDe mo main() is used to validate and verify
    * that all of the methods and data members of the class
    * do or contain what they are supposed.
    */
    public static void main(String[] args) {
    StudentRecord g1 = new StudentRecord() ;
    g1.set(8, 9, 76, 99);
    g1.writeOutput( );
    System.out.prin tln("StudentRec ordDemo done.");
    }

    public class StudentRecord {
    // data members:
    private int quiz1;
    private int quiz2;
    private int midterm;
    private int finalExam;
    private float finalGrade;
    private char letterGrade;


    // data methods:
    /**
    * StudentRecord.s et() allows for the direct unverified input of data
    * members of the class for use in testing and setting values.
    */
    public void set(int q1, int q2, int mt, int fE) {
    quiz1 = q1;
    quiz2 = q2;
    midterm = mt;
    finalExam = fE;
    finalGrade = computeFinalGra de();
    letterGrade = computeLetterGr ade();
    }

    public void writeOutput() {
    System.out.prin tln("Quiz 1 = " + quiz1);
    System.out.prin tln("Quiz 2 = " + quiz2);
    System.out.prin tln("Midterm Exam= " + midterm);
    System.out.prin tln("Final Exam = " + finalExam);
    System.out.prin tln("Final Grade = " + finalGrade + " or an ["
    + letterGrade + "]");
    }

    /**
    * StudentRecord.c omputeFinalGrad e() takes all test scores and provides the
    * final computed class grade.
    */
    private float computeFinalGra de() {
    double tempGrade = 0.125 * (quiz1 * 10); // first quiz part
    tempGrade += 0.125 * (quiz2 * 10); // second quiz part
    tempGrade += 0.25 * midterm; // midterm part
    tempGrade += 0.50 * finalExam; // final exam part
    return (float) tempGrade;
    }

    /**
    * StudentRecord.c omputeLetterGra de() provides correct letter grade for the
    * final grade provided.
    */
    private char computeLetterGr ade()
    {
    char tempGrade = '?';
    if (finalGrade >= 89.5)
    tempGrade = 'A';
    else if (finalGrade >= 79.5)
    tempGrade = 'B';
    else if (finalGrade >= 69.5)
    tempGrade = 'C';
    else if (finalGrade >= 59.5)
    tempGrade = 'D';
    else
    tempGrade = 'F';
    return tempGrade;
    }
    }
    Please use code tags for posting code next time you want to post code.
    For taking input from the user, you use java.util.Scann er.
    Since it's in the util package, you import it first before you use it
    Code:
    import java.util.Scanner;
    Then in your code you make the scanner as follows

    Code:
    Scanner input = new Scanner(System.in);
    meaning that it will read from the console.

    Here is how I would use it to read a double value:
    Code:
    System.out.println("Enter a double : ");
    double myDouble  = input.nextDouble();

    Comment

    Working...