Results 1 to 20 of 20
  1. #1
    Moltisanti is offline Member
    Join Date
    Aug 2009
    Posts
    19
    Rep Power
    0

    Default so very lost on school project....

    I am very very lost here....Java has always thrown me for a loop (no pun intended), but i am trying very hard to get through this class.

    Anyways, we need to make a program that prompts the user for their major, their gpa, tuition, etc....you will see.

    Then we are to print the average GPA, average Tuition, highest GPA for the math major, highest gpa for the CIS major, then list WHO had the highest gpa....etc etc etc....it's got my mind racing and I am extremely lost....

    Anyways, here's what I have so far..I'm sure to the experts it will look like a total mess....

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    String studentsLast, sGPA = null;
    String finalout="";
    String text;
    String scredits,sstudentsMajor = null;
    String credits;
    int studentsMajor = 0, i, large=0, gpa = 0;
    double cisGPA, mathGpa=0, cisGpa=0, avgGpa, Gpa=0, totalTuition=0, counter=0;
    double avgTuition=0, tuitionPaidfinal=0;
    //Choose major

    String output = "Please enter your major. Your choices are: " + "\n" +
    "1. Math " + "\n" +
    "2. CIS: " + "\n" +
    "0 - End Input" + "\n";
    String studentsMajorString = JOptionPane.showInputDialog(null,
    output, "Input Data",
    JOptionPane.QUESTION_MESSAGE);

    //convert to integer
    studentsMajor = Integer.parseInt(studentsMajorString);

    for(i=1;i>1;++i)


    while(studentsMajor != 0);
    {

    studentsLast = JOptionPane.showInputDialog(null,
    "Enter student's last name", "Input Data",
    JOptionPane.QUESTION_MESSAGE);


    String numberOfCreditsString = JOptionPane.showInputDialog
    ("Enter number of credits, " +
    "for example, 10: ");

    //Convert string to double
    double numberOfCredits = Double.parseDouble(numberOfCreditsString);


    output = "Enter GPA, for example, 3.2: ";
    String gpaString = JOptionPane.showInputDialog(null,
    output, "Input Data",
    JOptionPane.QUESTION_MESSAGE);
    //Convert to integer
    int gpa1 = Integer.parseInt(gpaString);

    output = "Enter tuition paid, for example, 23400: ";
    String tuitionPaidString = JOptionPane.showInputDialog(null,
    output, "Input Data:",
    JOptionPane.QUESTION_MESSAGE);
    //Convert to double
    double tuitionPaid = Double.parseDouble(tuitionPaidString);



    output = "Please enter your major. Your choices are: " + "\n" +
    "1. Math " + "\n" +
    "2. CIS: " + "\n" +
    "0 - End Input" + "\n";
    sstudentsMajor = JOptionPane.showInputDialog(null,
    output, "Input Data",
    JOptionPane.QUESTION_MESSAGE);

    //Convert to integer
    studentsMajor = Integer.parseInt(sstudentsMajor);
    } // while loop


    //Average GPA
    avgGpa = Gpa/i;

    //Average Tuition Paid
    avgTuition = tuitionPaidfinal / i;

    output = "The average GPA is: "+avgGpa + "\n";

    JOptionPane.showMessageDialog(null, output, " ",
    JOptionPane.INFORMATION_MESSAGE);

    output = "The average tuition paid is: "+avgTuition + "\n";

    JOptionPane.showMessageDialog(null, output, " ",
    JOptionPane.INFORMATION_MESSAGE);


    System.exit(0);
    }//main

    //class

    }

  2. #2
    Moltisanti is offline Member
    Join Date
    Aug 2009
    Posts
    19
    Rep Power
    0

    Default

    BTW, can't use an array...must use while loop.

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Please use code tags if you have to post code.
    Don't just dump your code and throw your hands in the air. Describe what is happening vs what must happen.

  4. #4
    Moltisanti is offline Member
    Join Date
    Aug 2009
    Posts
    19
    Rep Power
    0

    Default

    I apologize. Still new here.

    What is happening is pretty much nothing. My dialog boxes are not throwing out the average tuition nor the average GPA. That's all the further I have coded because I wanted to make certain I was doing it right. I guess I am not.

    Also, for some reason, after one cycle, i am exiting my loop. I need to stay in the loop until the user wishes to exit.

    I am just very confused right now.

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    The while loop condition controls whether the looping continues or not.
    Put println statements for the studentsMajor values to see what they are during execution.
    Also, why do you have a for loop around your while loop?
    Finally you never add any values at all in your loops so no totalling is ever being done.

  6. #6
    Moltisanti is offline Member
    Join Date
    Aug 2009
    Posts
    19
    Rep Power
    0

    Default

    So for the credits, my coding needs to be credits = 0.

    Correct?

    The for loop is an error...I was jumping around trying to figure out how to implement a counter to count the number of times the loop was used.

  7. #7
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    To find out how many times your loop ran, you just initialize an int, say count, before the while loop and do count++; inside the while loop. No need for any for another looping construct. Then inside your loop, you need to be getting input values and adding them to some variables declared before the loop.

  8. #8
    Moltisanti is offline Member
    Join Date
    Aug 2009
    Posts
    19
    Rep Power
    0

    Default

    It's still not staying in the loop. Added the counter...fixing the other things in the loop. Much thanks for all the info so far.

  9. #9
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Like I said, use println statements to see what the values are at each stage in the program.
    Make an effort to understand the out output you get from the printlns. If you get a compiler error, don't rush to post it here. Try to understand it and see if you can't finish it all yourself first.

  10. #10
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    Have you tried doign it with a do while?

    maybe thats easier? you can play endlessly with while loops :p

    little example

    Java Code:
    int count = 1;
              do {
                   System.out.println("Count is: " + count);
                   count++;
              } while (count <= 11);
         }
    }
    Just trying to make you think in other ways to do it.
    Programming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...

  11. #11
    Moltisanti is offline Member
    Join Date
    Aug 2009
    Posts
    19
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Like I said, use println statements to see what the values are at each stage in the program.
    Make an effort to understand the out output you get from the printlns. If you get a compiler error, don't rush to post it here. Try to understand it and see if you can't finish it all yourself first.
    That's just it. I'm not getting any compiler errors, I am just getting stuck on which code to use to get the desired results.

    Have been working and stuck on this for over 6 hours so it's not like I am getting an compiler error and then running for help.

  12. #12
    Moltisanti is offline Member
    Join Date
    Aug 2009
    Posts
    19
    Rep Power
    0

    Default

    Thank you for another perspective...I am thinking about just scrubbing the whole program and starting over.
    Last edited by Moltisanti; 09-22-2009 at 08:48 PM. Reason: spelling error

  13. #13
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    have you tried writing it out on a paper? when i lose grip on a project i try to run myself tru the code and write out how it should be. most of the time i solve my problem like that.
    Works for me, but hey thats just how i try to do it when i'm in this situation.

    try it and maybe you will see it

    all the best,

    Dieter
    Programming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...

  14. #14
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    by writing it on a paper i don't mean writing java code. i mean analysing like DFD's or NSD's or simple program steps.
    Programming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...

  15. #15
    Moltisanti is offline Member
    Join Date
    Aug 2009
    Posts
    19
    Rep Power
    0

    Default

    I have made tons of progress, but stuck at one last thing...I have to filter out the best GPA from the math student and the best GPA from the CIS student. I have no idea how to do that without using an array.

    I'm guessing it should be an if/while statement again....any suggestions?

  16. #16
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    Quote Originally Posted by Moltisanti View Post
    I'm guessing it should be an if/while statement again
    try it, who knows :)
    Programming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I have made tons of progress, but stuck at one last thing...I have to filter out the best GPA from the math student and the best GPA from the CIS student. I have no idea how to do that without using an array.

    I'm guessing it should be an if/while statement again....any suggestions?
    Your best bet here is to post your best effort at this, and let's see if we can help you progress from there. Much luck!

  18. #18
    gmacca is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default

    hey i think we are in the same class. i had the same exact assignment due tonight and get so far, then get stuck when it comes to getting the calculations from the loop inputs. good luck with yours!

  19. #19
    gmacca is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default

    oh, and needless to say, i didn't get it turned in by midnight when it was due. i'm nearly in tears over this project because there seems to be nothing in the book that is even close to what this assignment is asking for! Completely difficult for a java newbie like myself. This is my first java class.. I seemed fine with the assignments up until this one! Now I'm in a panic!

  20. #20
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    aww how cute, class buddies :p
    Programming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...

Similar Threads

  1. Need help with school work
    By ccfdet in forum New To Java
    Replies: 3
    Last Post: 08-29-2009, 07:14 PM
  2. Question about school assignment
    By wata in forum New To Java
    Replies: 7
    Last Post: 08-18-2009, 02:00 PM
  3. school project help
    By justin8790 in forum New To Java
    Replies: 5
    Last Post: 03-22-2009, 09:54 AM
  4. Beginner Needs Help w/ Program for School
    By badness in forum New To Java
    Replies: 2
    Last Post: 11-24-2007, 07:51 PM
  5. Please help... assignment for school
    By confused2000 in forum New To Java
    Replies: 3
    Last Post: 11-12-2007, 08:12 AM

Posting Permissions

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