Desperately need help with this HW problem on methods!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ccarter45
    New Member
    • Mar 2008
    • 10

    Desperately need help with this HW problem on methods!

    I guess I really don't have a good understanding of methods, it's really confusing for me. I'm not asking anyone to solve this for me, but any help would be GREATLY appreciated. This is the assignment:

    Method getIntBetween that gets user input for an integer within certain range. It receives a string, message, to be printed out as the prompt message, and two integer min and max that indicate the desired range of the input. It error-checks the user input, keeps asking for user input until a number within the range is entered. It then returns the number.
    Method printMenu prints out the main menu and gets user input of the choice for a menu item. It calls on getIntBetween to get an input in between 1 and 4. It then returns the number to the calling method (in this case, the main method).
    Method getRandom that generates a random number within certain range. It receives two integers, min and max, and returns a random number in the range [min, max].
    Three methods additionTutor, substractionTut or and multiplicationT utor that implements the tutoring tools for the operators. For each operator, generate 10 random problems. Call on getRandom to generate random numbers within the range 0 to 20 to use in the problems. For each problem, ask user input for an answer, then check if the answer is correct. Give the correct answer if the user’s answer is wrong.
    Sample Output (from one run of the program):
    Welcome to Math Tutor!
    1 - Addition
    2 - Subtraction
    3 - Multiplication
    4 - Quit
    Enter your choice of 1-4: 5
    Wrong input! Must enter a number between 1 and 4!
    Enter your choice of 1-4: 1
    Addition Tutor...
    What is 19 + 19? 38
    You are correct!
    What is 9 + 13? 21
    Sorry, the correct answer is 22.
    What is 14 + 8? 22
    You are correct!
    What is 19 + 4? 23
    You are correct!
    What is 12 + 2? 1
    Sorry, the correct answer is 14.
    What is 5 + 14? 19
    You are correct!
    What is 11 + 11? 22
    You are correct!
    What is 0 + 0? 0
    You are correct!
    What is 8 + 13? 21
    You are correct!
    What is 13 + 5? 18
    You are correct!


    Here's the code I have:
    Code:
    import java.util.Scanner;
      
    public class MathTutor
    {
      public static void main( String[] args ) 
      {  
        int choice;
        
        choice = printMenu();
        while (choice != 4)
        {
          if ( choice == 1 )
            additionTutor();
          else if ( choice == 2 )
            substractionTutor();
          else if ( choice == 3 )
            multiplicationTutor();
          
          choice = printMenu();  
        }
      }
      
      // method prints out the main menu and gets user choice for menu item  
      public static int printMenu()
      {
        System.out.println( "Welcome to Math Tutor!" );
        System.out.println( "1 - Addtion" );
        System.out.println( "2 - Substraction" );
        System.out.println( "3 - Multiplication" );
        System.out.println( "4 - Quit" );
        
        // Write your code here
      }
      
      // method gets user input for an integer in between min and max
      public static int getIntBetween( String message, int min, int max ) 
      {
        // Write your code here
      }
      
      // method generates a random number in between min and max
      public static int getRandom( int min, int max ) 
      {
        // Write your code here
      }
      
      // method implements addition tutor
      public static void additionTutor()
      {
        System.out.println( "Addition Tutor...\n" );
        // Write your code here
      }
      
      // method implements substraction tutor
      public static void substractionTutor()
      {
        System.out.println( "Substraction Tutor...\n" );
        // Write your code here
      }
      
      // method implements multiplication tutor
      public static void multiplicationTutor()
      {
        System.out.println( "Multiplication Tutor...\n" );
        // Write your code here
      }
    }
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    I hope this may help you...

    You may also read this if you want too...


    Don't worry, our experts here are ready to help you,
    Just ask a specific question with your best effort... ;-)


    Sukatoa...

    Comment

    • SammyB
      Recognized Expert Contributor
      • Mar 2007
      • 807

      #3
      Originally posted by ccarter45
      I guess I really don't have a good understanding of methods, it's really confusing for me. I'm not asking anyone to solve this for me, but any help would be GREATLY appreciated. This is the assignment: <snip>
      We will not write your code for you, so you'll need to ask specific questions. I would suggest drawing a flowchart or block diagram of the code that you were given and then begin to think about what needs to go into each piece. Don't worry, you'll survive. I'm in the second quarter of a Java class and I'm 62 years young! Keep thinking! --Sam

      Comment

      Working...