Results 1 to 9 of 9
Thread: Confusion with maths game?...
- 08-28-2011, 02:10 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 31
- Rep Power
- 0
Confusion with maths game?...
So, ive got a really simple maths game works fine and all. But there is just one thing wrong with it, its supposed to ask 10 question and then output how many you got wright out of 10, but the questions seem to never stop.
.gif)
Java Code:package apples; /** * @author Bimz */ public class Apples { public static void main(String[] args) { int numz = 0; System.out.println("Simple maths game! Enjoy!"); tuna tunaObject = new tuna(); while(numz <= 10) { tunaObject.Method(); numz++; } System.out.print("You got " + tunaObject.counter + " out of 10 right!"); } }
please helpJava Code:package apples; import java.util.Random; import java.util.Scanner; /** * @author Bimz */ public class tuna { Random random = new Random(); Scanner scan = new Scanner(System.in); public int counter = 0; private int rndm1; private int rndm2; private int lol; private int add; private int sub; private int mult; public int ans; private int correct; public Void Method(){ lol = 1 + random.nextInt(3); if(lol == 1) { //add rndm1 = 1 + random.nextInt(50); rndm2 = 1 + random.nextInt(50); correct = rndm1 + rndm2; System.out.println(rndm1 + " + " + rndm2); ans = scan.nextInt(); if(ans == correct) { counter += 1; System.out.println("You got it right!"); }else { System.out.println("You got it wrong :("); } }else if(lol == 2) { //sub rndm1 = 1 + random.nextInt(100); rndm2 = 1 + random.nextInt(100); if(rndm1 > rndm2){ correct = rndm1 - rndm2; System.out.println(rndm1 + " - " + rndm2); }else { correct = rndm2 - rndm1; System.out.println(rndm2 + " - " + rndm1); } ans = scan.nextInt(); if(ans == correct) { counter += 1; System.out.println("You got it right!"); }else { System.out.println("You got it wrong :("); } }else { //mult rndm1 = 1 + random.nextInt(6); rndm2 = 1 + random.nextInt(6); correct = rndm1 * rndm2; System.out.println(rndm1 + " * " + rndm2); ans = scan.nextInt(); if(ans == correct) { counter += 1; System.out.println("You got it right!"); }else { System.out.println("You got it wrong :("); } } return Method(); } }
thank you, Bimz
- 08-28-2011, 02:17 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 08-28-2011, 02:46 PM #3
- 08-28-2011, 03:00 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 08-29-2011, 04:34 AM #5
Member
- Join Date
- Aug 2011
- Posts
- 31
- Rep Power
- 0
when i remove the "return Method();" theres an error which says that there is no return statement for "Method()" so what would i have to enter instead?
thank you Bimz
- 08-29-2011, 04:49 AM #6
Remember that Java is case sensitive. Do you really want to return a Void object?Java Code:public Void Method(){
- 08-29-2011, 07:51 AM #7
You can't do that either.Do you really want to return a Void object?
dbThe Void class is an uninstantiable placeholder class ...
- 08-29-2011, 09:35 AM #8
Member
- Join Date
- Aug 2011
- Posts
- 31
- Rep Power
- 0
i was unsure of what to put, seen as ive got a scanner, and a string so i put void. should i return it as a string?
- 08-29-2011, 11:08 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
You have to make up your mind: what do you want to return, not what type should your method return. Do you want to signal the caller of that method that the user gave an (in)correct answer? If so, a boolean makes sense. If you want to return the points earned with that question, an int makes sense. It's up to you ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Help me with maths on my program!
By Ruuhkis in forum New To JavaReplies: 6Last Post: 02-17-2011, 06:27 AM -
Maths for programming
By ron2794 in forum New To JavaReplies: 3Last Post: 12-17-2010, 08:17 AM -
Maths Packages
By Anish in forum Advanced JavaReplies: 7Last Post: 11-27-2008, 06:46 AM -
Whats wrong with my maths???
By soc86 in forum New To JavaReplies: 4Last Post: 11-03-2008, 05:52 PM -
Maths table.. what am I doing wrong (probably everything!! :p )
By ad0m in forum New To JavaReplies: 15Last Post: 11-30-2007, 05:19 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks