473,325 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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, substractionTutor and multiplicationTutor 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:
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class MathTutor
  4. {
  5.   public static void main( String[] args ) 
  6.   {  
  7.     int choice;
  8.  
  9.     choice = printMenu();
  10.     while (choice != 4)
  11.     {
  12.       if ( choice == 1 )
  13.         additionTutor();
  14.       else if ( choice == 2 )
  15.         substractionTutor();
  16.       else if ( choice == 3 )
  17.         multiplicationTutor();
  18.  
  19.       choice = printMenu();  
  20.     }
  21.   }
  22.  
  23.   // method prints out the main menu and gets user choice for menu item  
  24.   public static int printMenu()
  25.   {
  26.     System.out.println( "Welcome to Math Tutor!" );
  27.     System.out.println( "1 - Addtion" );
  28.     System.out.println( "2 - Substraction" );
  29.     System.out.println( "3 - Multiplication" );
  30.     System.out.println( "4 - Quit" );
  31.  
  32.     // Write your code here
  33.   }
  34.  
  35.   // method gets user input for an integer in between min and max
  36.   public static int getIntBetween( String message, int min, int max ) 
  37.   {
  38.     // Write your code here
  39.   }
  40.  
  41.   // method generates a random number in between min and max
  42.   public static int getRandom( int min, int max ) 
  43.   {
  44.     // Write your code here
  45.   }
  46.  
  47.   // method implements addition tutor
  48.   public static void additionTutor()
  49.   {
  50.     System.out.println( "Addition Tutor...\n" );
  51.     // Write your code here
  52.   }
  53.  
  54.   // method implements substraction tutor
  55.   public static void substractionTutor()
  56.   {
  57.     System.out.println( "Substraction Tutor...\n" );
  58.     // Write your code here
  59.   }
  60.  
  61.   // method implements multiplication tutor
  62.   public static void multiplicationTutor()
  63.   {
  64.     System.out.println( "Multiplication Tutor...\n" );
  65.     // Write your code here
  66.   }
  67. }
Mar 1 '08 #1
2 1690
sukatoa
539 512MB
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...
Mar 1 '08 #2
SammyB
807 Expert 512MB
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
Mar 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Fabian | last post by:
Hi all there, I have already tried asking for help a couple of days ago. I try to rephrase better my problem: I need to grab a webpage that looks like this: <td width=80 align=center...
1
by: rdshultz | last post by:
I'm a complete newbie. Need to insert a Company logo into a database column to use later on in a check printing application. Read how to insert the pointer instead of the object into the column. ...
5
by: Rudy | last post by:
I am desperately seeking some help with a program that was supposed to have been completed last night. I have only been working with PHP for a week. I have tried and tried and tried, but I am...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
0
by: chrisben | last post by:
Hi, Developing Env: .NET Studio in C#, windows 2000 target: a COM object used for excel user (RTD) I have no problem to compile and run the project in my machine. The excel is working great...
17
by: EkteGjetost | last post by:
This is definitely not the smart thing to do as far as my learning goes, but desperate situations call for desperate measures. The final lab for my introduction to C programming class is due...
2
by: Lior | last post by:
Hi, I have an ASP.NET website that crashes under heavy load. I use a SQL Server DB. I get around 5500 hits per day. I keep getting the timeout expieried connection pool error. Sometimes it even...
10
by: Susan Baker | last post by:
Hi Guys (and girls), I am in a bit of a bind. I'm looking for a simple "proof of concept" C# app (WinForm OR console) that sends a web request to a simple PHP script and receives BINARY data...
6
by: NutsAboutVB | last post by:
Hello, I am a .NET programmer and I have a JPEG image file (from digital camera) of about 109 KB's in size, when I open it and save it (without making any alterations at all, just going to File...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.