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.


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
    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);
    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;
    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
    Eastern Florida
    Thanked 2,475 Times in 2,426 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:
    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, 11:20 AM
  2. Replies: 7
    Last Post: January 24th, 2013, 10: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, 04:38 PM
  4. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM