Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Idea's on what else to add?

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    11
    My Mood
    Amazed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Idea's on what else to add?

    I am new to Java and this is one of my first codes that I'm posting, its a 8ball that returns a random answer via the console. I was just wondering if there is anything on this code that I can improve to further my knowledge, any help would be great

    import java.util.Scanner;
     
    public class 8ball {
     
    	/**
    	 * Coded by Cody Reuille
    	 * 
    	 */
    	public static void main(String[] args) throws InterruptedException {
    		/**
    		 * adds Scanners to check if a question is asked and to see if you want
    		 * to ask another question
    		 */
    		Scanner question = new Scanner(System.in);
    		Scanner repeat = new Scanner(System.in);
    		// initiates the int used for the random number
    		int rndoutcome;
    		// while loop so you can ask more then one question without it
    		// terminating
    		while (true) {
    			System.out.println("Please state you're question.");
    			question.nextLine();
    			// sets rndoutcome to a random number 0-9
    			rndoutcome = (int) (Math.random() * 10);
    			// switch statement for random outcomes
    			switch (rndoutcome) {
    			case 0:
    				System.out.println("Nope.");
    				break;
    			case 1:
    				System.out.println("Anything is possible!");
    				break;
    			case 2:
    				System.out.println("Never!");
    				break;
    			case 3:
    				System.out.println("Yes!");
    				break;
    			case 4:
    				System.out.println("Please try again later.");
    				break;
    			case 5:
    				System.out.println("I dont feel like answering that...");
    				break;
    			case 6:
    				System.out.println("Not even in your dreams.");
    				break;
    			case 7:
    				System.out.println("Whats the answer im looking for? oh, NO!");
    				break;
    			case 8:
    				System.out.println("Maybe someday, but not today.");
    				break;
    			case 9:
    				System.out.println("This is correct.");
    				break;
    			}
    			// 2 second pause before asking if you want to ask another question
    			Thread.sleep(2000);
    			System.out.println("Would you like to ask another question? (Yes/No)");
    			// checks to see if you enter yes or no
    			if (!repeat.nextLine().equalsIgnoreCase("yes")) {
    				// if you type yes then it will repeat, if not it will terminate
    				break;
    			}
    		}
     
    	}
    }
    Last edited by CodyReuille; October 14th, 2011 at 05:31 PM. Reason: Updated


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Idea's on what else to add?

    Any ideas on what else to add and or change
    Add for what? What is the goal? You need to provide a lot more context...could be just me, but I am not very good at guessing
    Suggested reading: http://www.javaprogrammingforums.com...-get-help.html

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    11
    My Mood
    Amazed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Idea's on what else to add?

    Add for what? What is the goal? You need to provide a lot more context...could be just me, but I am not very good at guessing
    Suggested reading: http://www.javaprogrammingforums.com...-get-help.html
    Updated it describing what it is and what it does hope it helps some

Similar Threads

  1. Need idea's for my next project
    By ChristopherLowe in forum The Cafe
    Replies: 2
    Last Post: June 29th, 2011, 10:24 AM
  2. Football League Table - Idea's?
    By RSYR in forum Java Theory & Questions
    Replies: 1
    Last Post: December 15th, 2009, 07:43 PM