Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with Average and Variables Please =)

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help with Average and Variables Please =)

    I wanna add:
    system print of the average of all the scores that were entered.
    and a system print of the maximum of all the scores that were entered.

    Can anyone help me and add that in there? ive been trying for hours, even bought a java book. couldnt figure it out haha. And if they could explain what you did thanks!


    public static void main(String[] args) {
            // TODO code application logic here
         String fName = null;
         int count = 0; 
     
     
     
     
    Scanner scan = new Scanner(System.in);
     
    while ( fName != "stop" ) {
    System.out.println("Enter the user's score from 0 to 100 ");
    System.out.println("....or you can always enter STOP to quit the app.");
    System.out.println("So far you have entered only " + count + " grades.");
    System.out.print("\nINPUT: ");
    int score = scan.nextInt();
     
    count++;
     
    if (score >= 101) {
    System.out.println("Too high!");
     
    else
     
     
    switch(score / 10)
      {
      case 10:
      case 9: System.out.println("Letter grade is A\n");
      break;
      case 8: System.out.println("Letter grade is B\n");
      break;
      case 7: System.out.println("Letter grade is C\n");
      break;
      case 6: System.out.println("Letter grade is D\n");
      break;
      default: System.out.println("Letter grade is F\n");
    }
        }
      }
    }
    Last edited by Raymond Pittman; October 8th, 2011 at 06:45 PM.


  2. #2
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Help with Average and Variables Please =)

    If you want to figure out the average. First know the formula.. Surely you know this (sum of values / # of values).. I'm sure you can go from there.. (if you wrote this code on your own)

    G'luck, comment back if you have any questions.
    Simplicity calls for Complexity. Think about it.

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help with Average and Variables Please =)

    Well, yes i believe its something like

     
    int average = (count / scores)

    but i couldnt remember where to put it, also i couldn't remember how to display max score =S

    help please. i tried for hours haha. my minds been blank but yes i did write this

  4. #4
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Help with Average and Variables Please =)

    Well, you have the variables switched around.. It would be this
    int average = scoreSum/count
    In order to get the Sum of the Scores, you have to add them to a variable each time you get a score in.
    So basically, here's the logic:
    I have a count variable of length (let's make something up) 5.
    Therefore, I must have 5 scores.
    If I want to get the average, I must find the sum of the scores.
    The score variable changes every time I run my loop, so simply multiplying the score by 5 at the end won't work.
    So in all, I must find a way that I can add each individual score to "something" 5 times... You can go from here, it's best to learn from Trial & Error



    And if you want to display the maximum grade, you have to have a variable that changes every time a higher number comes..
    This concept is a little harder, but first, try to get the Average section working.
    Simplicity calls for Complexity. Think about it.

Similar Threads

  1. Moving Average
    By Donieob in forum What's Wrong With My Code?
    Replies: 0
    Last Post: September 3rd, 2011, 08:58 AM
  2. Calculating average of an array
    By Vika in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 29th, 2011, 08:06 AM
  3. Something wrong with computing the average
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 18th, 2010, 07:51 AM
  4. Finding the Average
    By KiwiFlan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 16th, 2010, 07:58 PM
  5. Moving average
    By bondage in forum Loops & Control Statements
    Replies: 0
    Last Post: May 7th, 2010, 04:20 AM

Tags for this Thread