Results 1 to 4 of 4
  1. #1
    vesperia's Avatar
    vesperia is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Need help with my codes

    hi im a first year college student and im new to Java. And this is our first assignment, Create a program that will compute the average grade, equivalent and remarks of student using whileloop and dowhile loop. And here's what i've done so far:

    package Whileloop;

    public class yourGrades {

    public float prelimGrades = 0.0F;
    public float midtermGrades = 0.0F;
    public float finalGrades = 0.0F;
    public float averageGrades = 0.0F;
    public double[] equivalent = new double[10];
    public String[] remark = new String[10];


    public void showAll() {

    averageGrades = (prelimGrades + midtermGrades + finalGrades) / 3;
    System.out.println("\nAverage grade: " + averageGrades);

    equivalent[0] = 1;
    equivalent[1] = 1.25;
    equivalent[2] = 1.50;
    equivalent[3] = 1.75;
    equivalent[4] = 2;
    equivalent[5] = 2.25;
    equivalent[6] = 2.50;
    equivalent[7] = 2.75;
    equivalent[8] = 3;
    equivalent[9] = 5;

    remark[0] = "EXCELLENT";
    remark[1] = "VERY GOOD";
    remark[2] = "VERY GOOD";
    remark[3] = "GOOD";
    remark[4] = "GOOD";
    remark[5] = "FAIR";
    remark[6] = "FAIR";
    remark[7] = "PASSING";
    remark[8] = "PASSING";
    remark[9] = "FAILED";

    if (averageGrades >= 98 && averageGrades <= 100) {
    System.out.println("Equivalent: " + equivalent[0]);
    System.out.println("Remark: " + remark[0]);
    } else if (averageGrades >= 96) {
    System.out.println("Equivalent: " + equivalent[1]);
    System.out.println("Remark: " + remark[1]);
    } else if (averageGrades >= 93) {
    System.out.println("Equivalent: " + equivalent[2]);
    System.out.println("Remark: " + remark[2]);
    } else if (averageGrades >= 90) {
    System.out.println("Equivalent: " + equivalent[3]);
    System.out.println("Remark: " + remark[3]);
    } else if (averageGrades >= 87) {
    System.out.println("Equivalent: " + equivalent[4]);
    System.out.println("Remark: " + remark[4]);
    } else if (averageGrades >= 84) {
    System.out.println("Equivalent: " + equivalent[5]);
    System.out.println("Remark: " + remark[5]);
    } else if (averageGrades >= 81) {
    System.out.println("Equivalent: " + equivalent[6]);
    System.out.println("Remark: " + remark[6]);
    } else if (averageGrades >= 78) {
    System.out.println("Equivalent: " + equivalent[7]);
    System.out.println("Remark: " + remark[7]);
    } else if (averageGrades >= 75) {
    System.out.println("Equivalent: " + equivalent[8]);
    System.out.println("Remark: " + remark[8]);
    } else if (averageGrades <= 74) {
    System.out.println("Equivalent: " + equivalent[9]);
    System.out.println("Remark: " + remark[9]);
    }
    }

    }
    __________________________________________________ ________________________________
    package Whileloop;
    import java.io.*;
    public class yourGradesTest {



    public static void main(String[] args) throws IOException {

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    yourGrades yg = new yourGrades();

    int x = 1;
    while (x < 5) {
    x++;


    System.out.print("\nEnter your Prelim Grades: ");
    yg.prelimGrades = Float.parseFloat(reader.readLine());

    System.out.print("Enter your Midterm Grades: ");
    yg.midtermGrades = Float.parseFloat(reader.readLine());

    System.out.print("Enter your Final Grades: ");
    yg.finalGrades = Float.parseFloat(reader.readLine());

    yg.showAll();
    }

    }
    }
    __________________________________________________ _________________________________
    package DoWhileloop;

    public class yourGrades1 {


    public float prelimGrades = 0.0F;
    public float midtermGrades = 0.0F;
    public float finalGrades = 0.0F;
    public float averageGrades = 0.0F;
    public double[] equivalent = new double[10];
    public String[] remark = new String[10];

    public void showAll() {

    averageGrades = (prelimGrades + midtermGrades + finalGrades) / 3;
    System.out.println("\nAverage grade: " + averageGrades);

    equivalent[0] = 1;
    equivalent[1] = 1.25;
    equivalent[2] = 1.50;
    equivalent[3] = 1.75;
    equivalent[4] = 2;
    equivalent[5] = 2.25;
    equivalent[6] = 2.50;
    equivalent[7] = 2.75;
    equivalent[8] = 3;
    equivalent[9] = 5;

    remark[0] = "EXCELLENT";
    remark[1] = "VERY GOOD";
    remark[2] = "VERY GOOD";
    remark[3] = "GOOD";
    remark[4] = "GOOD";
    remark[5] = "FAIR";
    remark[6] = "FAIR";
    remark[7] = "PASSING";
    remark[8] = "PASSING";
    remark[9] = "FAILED";

    if (averageGrades >= 98 && averageGrades <= 100) {
    System.out.println("Equivalent: " + equivalent[0]);
    System.out.println("Remark: " + remark[0]);
    } else if (averageGrades >= 96) {
    System.out.println("Equivalent: " + equivalent[1]);
    System.out.println("Remark: " + remark[1]);
    } else if (averageGrades >= 93) {
    System.out.println("Equivalent: " + equivalent[2]);
    System.out.println("Remark: " + remark[2]);
    } else if (averageGrades >= 90) {
    System.out.println("Equivalent: " + equivalent[3]);
    System.out.println("Remark: " + remark[3]);
    } else if (averageGrades >= 87) {
    System.out.println("Equivalent: " + equivalent[4]);
    System.out.println("Remark: " + remark[4]);
    } else if (averageGrades >= 84) {
    System.out.println("Equivalent: " + equivalent[5]);
    System.out.println("Remark: " + remark[5]);
    } else if (averageGrades >= 81) {
    System.out.println("Equivalent: " + equivalent[6]);
    System.out.println("Remark: " + remark[6]);
    } else if (averageGrades >= 78) {
    System.out.println("Equivalent: " + equivalent[7]);
    System.out.println("Remark: " + remark[7]);
    } else if (averageGrades >= 75) {
    System.out.println("Equivalent: " + equivalent[8]);
    System.out.println("Remark: " + remark[8]);
    } else if (averageGrades <= 74) {
    System.out.println("Equivalent: " + equivalent[9]);
    System.out.println("Remark: " + remark[9]);
    }
    }
    }
    __________________________________________________ _________________________________

    package DoWhileloop;
    import java.io.*;
    public class yourGrades1Test {


    public static void main(String[] args) throws IOException {

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    yourGrades1 yg1 = new yourGrades1();

    int x = 1;
    do {
    x++;


    System.out.print("\nEnter your Prelim Grades: ");
    yg1.prelimGrades = Float.parseFloat(reader.readLine());

    System.out.print("Enter your Midterm Grades: ");
    yg1.midtermGrades = Float.parseFloat(reader.readLine());

    System.out.print("Enter your Final Grades: ");
    yg1.finalGrades = Float.parseFloat(reader.readLine());

    yg1.showAll();

    } while (x < 5);
    }
    }


    now my question is how can i make my codes more interesting like having a pop up box when asking to enter the name and the prelim, midterm, final grades? thank you very much !!!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default

    Please wrap your code in code tags when posting it. See: BB Code List - Java Forums
    Or use the # icon above the input box.

    For popup/dialog boxes to get user input, see the JOptionPane class. There are many code samples on this forum if you do a Search.

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    Quote Originally Posted by vesperia View Post
    now my question is how can i make my codes more interesting like having a pop up box when asking to enter the name and the prelim, midterm, final grades? thank you very much !!!
    That's the spirit. Like Norm said, JOptionPane is going to be your friend here: How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    You might also want to check out the API: Java Platform SE 6
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    vesperia's Avatar
    vesperia is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

Similar Threads

  1. I need some codes
    By johnmergene in forum New To Java
    Replies: 11
    Last Post: 01-25-2011, 03:42 AM
  2. What do the following codes do?
    By javaguy2 in forum New To Java
    Replies: 2
    Last Post: 01-23-2011, 10:23 PM
  3. How do I integrate these two codes?
    By Isong in forum AWT / Swing
    Replies: 3
    Last Post: 11-03-2010, 02:44 AM
  4. java codes
    By Balajee in forum AWT / Swing
    Replies: 1
    Last Post: 09-30-2008, 05:04 PM
  5. Assistant on my codes. SOS!!
    By sya1912 in forum Java Applets
    Replies: 16
    Last Post: 09-01-2008, 02:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •