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 2 of 2

Thread: can somebody help me with this code

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default can somebody help me with this code

    import java.util.Scanner;
    import java.util.Random;
    import java.applet.Applet;
    import java.awt.*;
    public class Magic8Ball{
    public static void main(String []args) {
    String question;
    Scanner scan = new Scanner(System.in);
    Random generator = new Random();
    System.out.println("Ask away. (Preferably yes or no questions");
    question = scan.next();
    Answer quest = new Answers(generator.nextInt(20)+1);
    System.out.println(quest.answers());
    }
    public class Answer{
    private int selection;
    private String response;

    public void Answers (int x) {
    selection = x;
    }

    public String Answer() {
    switch (selection) {
    case 1: response = "It is certain"; break;
    case 2: response = "It is decidedly so"; break;
    case 3: response = "Without a doubt"; break;
    case 4: response = "Yes definitely"; break;
    case 5: response = "You may rely on it"; break;
    case 6: response = "As I see it, yes"; break;
    case 7: response = "Most likely"; break;
    case 8: response = "Outlook good"; break;
    case 9: response = "Signs point to yes"; break;
    case 10: response = "Yes"; break;
    case 11: response = "Reply hazy, try again"; break;
    case 12: response = "Ask again later"; break;
    case 13: response = "Better not tell you now"; break;
    case 14: response = "Cannot predict now"; break;
    case 15: response = "Concentrate and ask again"; break;
    case 16: response = "Don't count on it"; break;
    case 17: response = "My reply is no"; break;
    case 18: response = "My sources say no"; break;
    case 19: response = "Outlook not so good"; break;
    case 20: response = "Very doubtful"; break;
    default: response = "nothing";
    }
    return response;
    }
    }
    public class DrawBallextendsApplet {
    public void paint(Graphics page) {
    final int MID =150;
    setBackground(Color.cyan);
    page.setColor(Color.black);
    page.fillOval(0,0,300,300);
    page.setColor(Color.blue);
    page.fillOval(75,60,150,150);
    page.setColor(Color.white);
    page.drawLine(MID-65,100, MID+65,100);
    page.drawLine(MID-65,100, MID,210);
    page.drawLine(MID+65,100, MID,210);
    }

    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,232
    Thanks
    52
    Thanked 2,296 Times in 2,267 Posts

    Default Re: can somebody help me with this code

    What problems are you having?

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: January 24th, 2013, 10:20 AM
  2. Replies: 7
    Last Post: January 24th, 2013, 09:41 AM
  3. Trouble Porting my Java File Reading Code to Android Code
    By Gravity Games in forum Android Development
    Replies: 0
    Last Post: December 6th, 2012, 03:38 PM
  4. Replies: 5
    Last Post: November 14th, 2012, 09:47 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM