473,739 Members | 5,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Novice needs help with maths quiz program

1 New Member
Hello all,
For the record I am a complete java novice.

I have to write a program to generate/output to screen 10 simple maths question and output a final score . The question is as follows

Random number, Random operator (+ or -) random number.

I have written the program but cannot make the random operator work. Can anyone help?

My code.

a = myRandom.nextIn t(8) +11;//generates random number
b = myRandom.nextIn t(8) +1;//generates 2nd random number

if(b<4)//this code sets random operator + or -
{
t='-'; // t is the random operator
}
else
{
t='+';
}
System.out.prin t("Question "+p+": "+((a+t+b)+ "= ? "));//prints question to screen

Thanks
Dec 2 '06 #1
1 3000
sicarie
4,677 Recognized Expert Moderator Specialist
Hello all,
For the record I am a complete java novice.

I have to write a program to generate/output to screen 10 simple maths question and output a final score . The question is as follows

Random number, Random operator (+ or -) random number.

I have written the program but cannot make the random operator work. Can anyone help?

My code.

a = myRandom.nextIn t(8) +11;//generates random number
b = myRandom.nextIn t(8) +1;//generates 2nd random number

if(b<4)//this code sets random operator + or -
{
t='-'; // t is the random operator
}
else
{
t='+';
}
System.out.prin t("Question "+p+": "+((a+t+b)+ "= ? "));//prints question to screen

Thanks
TwistedSpanner-

Here is a tutorial on random numbers in Java, if you think you have everything right, please post your entire program, and any error messsages you are getting, or what the current output is.

http://www.cs.geneseo.edu/~baldwin/r...ce/random.html
Dec 4 '06 #2

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

Similar topics

20
6561
by: __PPS__ | last post by:
Hello everybody in a quiz I had a question about dangling pointer: "What a dangling pointer is and the danger of using it" My answer was: "dangling pointer is a pointer that points to some area of ram that's not reserved by the program. Accessing memory through such pointer is likely to result in core dump (memory access violation)"
0
1091
by: gj | last post by:
Hi, Can I use a select statement with a RowFilter? I have a dropdownlist that is bound to the Quiz table. The quiz table has Quiz_ID, Quiz_Name, Quiz_Number, Quiz_Version and other fields. Quiz_ID is the primary key. Quiz_Number was the primary key to the original quiz and Quiz_Version is the version of the quiz. What I do is create a Quiz called Dog. I decide to edit the quiz Dog. I pull up Dog edit, my field and save. When I save it,...
3
2421
by: vengeboyz | last post by:
Hi everybody, My name's Jack and I'm a newbie in this forum... Nice to meet you all and i hope i can get along in this forum... And I also hope that you can help me with my problem... I'm a very beginner programmer that still learn in C language programming taht I hope I can be an advanced programmer or even expert programmer later :) I have a quiz from my author before and until now I still can't describe how to make this program... ...
4
1395
by: Chelonian | last post by:
I'm considering trying to learn Python for a specific reason, and hoped the group might help me get a sense for whether it would be worth my time. The situation... Me: total beginner w/ a sense of programming basics and 1 week familiarizing myself with Python world. Use WinXP. Got Python 2.5. Fooled around in IDLE, made "hello world!" and one which takes user input and tracks a string or two. Project: ambitious GUI program for...
4
12980
by: hjc | last post by:
i am trying to created a program that will write a grading program for a class with the following policies there are 2 quizzes each graded on the basis of 10 points there is 1 midterm and 1 final each graded on 100 points the final exam counts for 50% of the grade, the midterm counts for 25% and the 2 quizzes togehter count for a total of 25%(i have to normailze the scores) letter grades based on 90-100 A 80-89 B 70-79 C
1
1385
by: ray2007colon | last post by:
I need to now how to compare the elements of two arrays. Here is my program. Now I need to compare each element. So I can print the arrays and the elements that are not the same. import java.util.*; public class Grades { public static void main(String args) { Scanner keyboard = new Scanner(System.in);
1
1976
by: bikash607 | last post by:
Dear Expert, i m from very backward place in Bhutan and i need your assistance for a quiz program. I am trying to build a quiz program in Flash 6.0 and if you have any samples, please let me know....i will try my own but i didn't get any idea. Please help and I would remain thankful forever
5
2155
by: saytri | last post by:
Hi i have this project were i have to do a quiz. i wrote the questions in a textfile and i called them through java. I have also made a menu to choose which type of quiz. But before accessing the quiz i have to do a password and a login. I managed to do the password but when i tried to join this to the whole program its not working. This is the main program: import java.util.*; import java.io.*; import java.util.Scanner; import...
1
1918
by: saytri | last post by:
I have a problem with this code. I'm, doing a quiz, and the questions are stored in a binary file. My problem is how am i going to compare the answers entered by the user to the correct answers. The correct answers are stored in an array. Pls can someone help me with this code, because i'm really stuck. I think the problem is in the for loop (the code below). Thanks a lot. If you help me with examples of source code, i appreciate it a lot....
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.