-1
public class QuestionBank {  

    public static void main(String[] args) {

        int k = 0;

        String Bank[][] = {{"The sun is hot.","A. True","B. Flase","A"},
           {"Cats can fly.","A. True","B. False","B"}};
    }
}

Above is my QuestionBank class that creates a 2X4 string array. First column being the question, 2nd and 3rd being the answer choices, and 4th being the correct answer.

Below is my RealDeal class.

import javax.swing.JOptionPane;
import java.util.Scanner;

public class RealDeal {
    public static void main(String[] args) {

        input = JOptionPane.showInputDialog(Bank[0][0]\nBank[0][1]\nBank[0][2]);
        if (input == Bank[0][3]) {
            input = 10;
        } else {
            input = 0;
        }

        total = input/1;

        JOptionPane.showMessageDialog(null,"You scored a " + total + " out of 10. Great job!");

        System.exit(0);
    }
}

What I'm trying to do is to get Bank[0][0], Bank[0][1], and Bank[0][2] to output on my RealDeal class and then to check whether Bank[0][3] matches with the users input. Can anyone please help me with this. Im really new to java so if anyone could actually draw out the answer and explain it to me that would be great.

Drew Kennedy
  • 4,118
  • 4
  • 24
  • 34
Blue
  • 9
  • 5
  • possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – azurefrog Dec 08 '14 at 19:51
  • If this is all in one project, a project can only have one `main()` method. – Drew Kennedy Dec 08 '14 at 19:53
  • Also, assuming `input` is a `String` (since it's initially assigned with the output from `JOptionPane.showInputDialog(...)`), you cannot assign an `int` value to it (`input = 10; // won't compile`). – azurefrog Dec 08 '14 at 19:54
  • yea I know. The RealDeal class isn't completely accurate. Its just a quick example I did just to show people how I want it to run when it is constructed properly. – Blue Dec 08 '14 at 20:09

2 Answers2

0

I think the best way is reading a good Java book and become familiar with the language itself and then try to solve this by your own. If you then have a real question there is no problem asking it here again. But your code is... not really working at all. I don't think this portal is a "please do my work for me" portal.

Martin Fernau
  • 787
  • 1
  • 6
  • 19
  • Well yea the RealDeal class isn't working because I did a quick example of how I want it to run when it is constructed right. I got a huge project I'm doing and its too much stuff for me to put on this so I did this small example which is a part of my pjt. All I want to know is how to output Bank[0][0] in the RealDeal JOptionPane output part. That's all...I've put multiple questions up on the site before and have yet to receive help, and your "please do my work for me" is a prime example. If you don't wanna help, then don't comment. All I need is a LITTLE help on the output part and that's it. – Blue Dec 08 '14 at 20:05
  • How do you output Bank[0][0] in the ....part of input = JOptionPane.showInputDialog(....); that's all im asking, not for yall to do it for me – Blue Dec 08 '14 at 20:07
  • If you just want to ask the user for A or B and use the Text of your "Bank"-Array you need to concaternate the Text like this: `JOptionPane.showInputDialog(Bank[0][0] + "\n" + Bank[0][1] + "\n" + Bank[0][2]);` – Martin Fernau Dec 08 '14 at 20:12
0

To call anything from another class you will need to either setup a method for a return or make the variables public.

So:

public class Class1
{
    // for method 1
    public String s1 = "This is a string"

    // for method 2
    public Class1 {}

    public returnString()
    { 
         return s1;
    }
}

public class CLASS2
{
   public static void main(String args[])
   {
       // get the class
       cls1 = new Class1();

      // retrieving - method 1
      String str = cls1.s1;

      // retrieving - method2
      str = cls1.returnString();
   }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
bakriawad
  • 345
  • 2
  • 10