Welcome to Dream.In.Code
Become a Java Expert!

Join 149,598 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,905 people online right now. Registration is fast and FREE... Join Now!




Homework Problem

 
Reply to this topicStart new topic

Homework Problem, Find the minimum, maximum, average

carmwood
9 Oct, 2007 - 05:33 AM
Post #1

New D.I.C Head
*

Joined: 9 Oct, 2007
Posts: 1


My Contributions
Do not know how to combine three methods. I have only worked on building one method at a time. Not sure how to incorporate two other methods.

Using jGrasp

first try:
CODE

import java.util.Scanner;

public class Test
{
     public void main( String arg[] )
     {
         Scanner input = new Scanner( System.in )
  
          int grade;
          int gradeCounter;
          int total = 0;
          int average;
          int minimum;
          int maximum;

          System.out.print( "Enter grade or -1 to quit: " );
          grade = input.nextInt();

           while ( grade != -1 )
           {
                total = total + grade;
                gradeCounter = gradeCounter + 1;

                 System.out.print( "Enter grade -1 to quit: " );
                 grade = input.nextInt();
             } // end while

            if ( gradeCounter != 0 )
            {
                 average = total / gradeCounter;
          
                  System.out.printf ( "Average is: %2f\n", average );
             } // end if

             else
                 System.out.println( "No grades were entered" );

This is where I get lost tried using a for statement to find the minimum but the editor said that I was using a boolean instead of an int. not sure how to continue.....
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Homework Problem
9 Oct, 2007 - 05:50 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Next time please use code tags.
Also, please post your for statement, so we can tell you what's wrong with it.
Hint: you can find the minimum/maximum right after reading in the next value if you compare it to the current minimum/maximum so you don't need an additional loop (however for educational purposes it might worth to create it anyway wink2.gif ).
User is offlineProfile CardPM
+Quote Post

Programmist
RE: Homework Problem
9 Oct, 2007 - 06:27 AM
Post #3

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,250



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
In general, to combine methods, take the input parameters from methods M1(S1 = X1, X2, ..., Xk) ... Mn(Sn = X1, X2, ..., Xk) (all parameters of all methods) and take the union of those sets to be the input parameters to your combined method, Mc(Pc = S1 U S2 U ... U Sn-1 U Sn). Then, take the union of all operations on input parameters within M1 ... Mn, and put them in Mc, paying particular attention to any need for particular ordering of these operations.

This post has been edited by Programmist: 9 Oct, 2007 - 06:29 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:40PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month