Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2007, 03:13 AM
Member
 
Join Date: Dec 2007
Posts: 1
TKI5 is on a distinguished road
New User
Dear
All

Could anyone help me please i have written a piece of code

Code:
import javax.swing.JOptionPane; public class Maths { int UserID = 0; float result = 0.0f; int countnum = 0; int count = 0; int countTrys = 0; public void result () { JOptionPane.showMessageDialog ( null ,"You Got " + (result/countTrys) + "% Right"); JOptionPane.showMessageDialog ( null , "Number of Correct Answers " +count); JOptionPane.showMessageDialog ( null , "Number of Attempts " +countTrys); } public static void main(String[] args) { Maths m = new Maths (); m.choice(); m.result (); } public void choice () { int userChoice; String userChoiceString; do { userChoiceString = JOptionPane.showInputDialog("Enter your choice [1-5] \n 1.Mulitplication \n 2. Number of Correct answers and percentage \n 5. Exit"); userChoice = Integer.parseInt (userChoiceString); if ( userChoice == 1 ) { ++countTrys; ++count; multiplication (); } else if( userChoice == 2 ) { ++countnum; countnum = count/countTrys; result(); } } while ( userChoice != 5 ); } public void multiplication() { int multiplicationData, genNumOne, genNumTwo; String selectMultiplication; genNumOne = (int) ( Math.random() * 12); genNumTwo = (int) (Math.random() * 12); selectMultiplication = JOptionPane.showInputDialog("What is" + " " + genNumOne + " " + "times" + " " + genNumTwo); multiplicationData = Integer.parseInt(selectMultiplication); if ( multiplicationData == (genNumOne * genNumTwo) ) { JOptionPane.showMessageDialog ( null ,"Very Good" ); result = result + 100.0f; } else { JOptionPane.showMessageDialog ( null ,"Wrong Answer" ); } } }
but know i am tying to extend the program to keep track of the name of the current user. Add an extra menu item, option 3, to change the user. When a user changes, the name of the new user should be read in and the number of attempts and the number of correct answers should both be reset to 0. I am need to modifiy the code associated with menu item 2 to output the name of the user in addition to the other information.

Also i need to extend your program to keep track of the top five percentages and the names of the users who achieved them. In order to do this you should use arrays; one to store the percentages and the other to store the names. The two arrays can be initialised with five users each with the name “nobody” and a percentage of 0. Each time that the user changes the user should be added to the high score arrays if they have made more than 10 attempts and their percentage of correct answers is greater than one of the entries in the current top five. Add an extra menu item, option 4, to display the top five high scores and names of the corresponding users.


Using %12 gives the remainder on dividing the random integer by 12; this could be a psoitvie or negative number in the range 0 – 11. Adding 1 ensures it is from 1 – 12. Using Math.abs ensures that it is positive.

A variation of one pass of the bubble sort is one way to add a high score in its correct position in the array. If the high score array is in descending order then one way to add a new high score would be as follows. Compare the current score with the last entry in the array. If it is bigger then it should be in the high score table, bubble it to its correct position. Consider a current score of 52% for Joe being added to the following arrays.\:

Names Liz Adam Henry Sarah Dan
Scores 84 75 51 49 47
After first comparison:
Names Liz Adam Henry Sarah Sarah
Scores 84 75 51 49 49
After second comparison:
Names Liz Adam Henry Henry Sarah
Scores 84 75 51 51 49
Now Joe is added
Names Liz Adam Joe Henry Sarah
Scores 84 75 52 51 49


If anyone could help that would be fantastic.

Thank you all

Last edited by JavaBean : 12-13-2007 at 07:51 AM. Reason: [code] tag is fixed.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the User Name Java Tip java.lang 0 04-04-2008 04:43 PM
cant take input from user new_1 New To Java 6 12-25-2007 09:38 AM
Getting current user’s name Java Tip Java Tips 0 12-07-2007 02:04 PM
How to get the User Name JavaBean Java Tips 0 10-04-2007 11:35 PM
Help user interface carl New To Java 1 07-31-2007 09:58 PM


All times are GMT +3. The time now is 04:00 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org