package wow;

import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Wow
{
String question;
String answer;
int correct=0, number=15;
Wow[] quizBank = new Wow[15];
List<Wow> quizList = Arrays.asList(quizBank);

public static void main(String[] args)
{
Wow bank = new Wow();
bank.bankList();
bank.askQuestion();
} //end main

public void bankList()
{
quizBank[1] = new Wow();
quizBank[1].question = "A version of Windows released in October 15 2001";
quizBank[1].answer = "windows xp";

quizBank[2] = new Wow();
quizBank[2].question = "It is the world's first multi-touch smartphone released in June 29 2007";
quizBank[2].answer = " iphone";

quizBank[3] = new Wow();
quizBank[3].question = "It is the first quad core processor released by intel";
quizBank[3].answer = "core 2 quad";

quizBank[4] = new Wow();
quizBank[4].question = "He is the chief architech of the linux kernel";
quizBank[4].answer = "linus tolvards";

quizBank[5] = new Wow();
quizBank[5].question = "He is the founder of Microsoft";
quizBank[5].answer = "bill gates";

quizBank[6] = new Wow();
quizBank[6].question = "It is the first multitouch tablet relased by apple";
quizBank[6].answer = "ipad";

quizBank[7]= new Wow();
quizBank[7].question = "Its is the latest version and codename of android";
quizBank[7].answer = "4.2.2 jelly bean";

quizBank[8] = new Wow();
quizBank[8].question = "It is the operating system of iphone/ipad";
quizBank[8].answer = "ios";

quizBank[9] = new Wow();
quizBank[9].question = "Its the latest version and codename of mac os x";
quizBank[9].answer = "10.8 mountain lion";

quizBank[10] = new Wow();
quizBank[10].question = "how old is the microsoft corporation";
quizBank[10].answer = "35";

quizBank[11] = new Wow();
quizBank[11].question = "What is the latest version and codename of ubuntu linux";
quizBank[11].answer = "12.10 quantal quetzal";

quizBank[12] = new Wow();
quizBank[12].question = "it is the first computer that has a graphical users interface released by apple in 1984";
quizBank[12].answer = "macintosh";

quizBank[13] = new Wow();
quizBank[13].question = "he is the current ceo of google inc.";
quizBank[13].answer = "larry page";

quizBank[14] = new Wow();
quizBank[14].question = "A version of windows released in 2007";
quizBank[14].answer = "windows vista";
Collections.shuffle(quizList);
}

public void askQuestion()
{
Scanner input = new Scanner(System.in);
System.out.println("****************************** **");
System.out.println(" Welcome to TECH QUIZ");
System.out.println("****************************** **");

for (number=1; number<15; number++)
{
        PrintStream printf;
        printf = System.out.printf("%d. %s?%n", number, quizBank[number].question);
String entered = input.nextLine();

if (entered.compareTo(quizBank[number].answer)==0)
{
System.out.println("*** Correct! ***");
correct = correct + 1;
}
else {
System.out.println("--- Incorrect! ---");

}
}

System.out.println("*******************");
System.out.printf(" Your score is %d/%d%n", correct, number);

System.out.println("*******************");
}

}

my program work but with errrors in line 94 and 21 how do i get rid of the problem?
and also how can i make my program display the correct answer in every item if the inputted answers is incorrect? thanks

Edited 3 Years Ago by darylglenng: typo

your code is filled with errors, and a lot more then you imagine.
just saying "it shows an error" doesn't say anything. what error does it show?
also: don't use the '==' operators to compare Strings, unless you want your application to work in a way you don't expect/want it to work.

this may answer your question =)
Exception in thread "main" java.lang.NullPointerException
at wow.Wow.askQuestion(Wow.java:94)
at wow.Wow.main(Wow.java:21)
Java Result: 1

don't use the '==' operators to compare Strings, unless you want your application to work in a way you don't expect/want it to work.

That's a bit cryptic!
== tests for two objects being exactly the same object. For Strings you want to know if those two different String objects contain the same text (sequence of characters). For that you use the equals method, eg string1.equals(string2)

Edited 3 Years Ago by JamesCherrill

that means you are using a not instantiated instance somewhere.
I tried running without the Collections.shuffle call, then it works.

but another remark, it's best to keep your instance variables private, and only accessible through mutators (setters & getters)

hai darylglenng

i got the answer for your problem (if my assumption is right) and what you just need to do is

add 1 more question to your existing questions list with the same index 0 as follows (try to copy and paste it to your code as it is)

quizBank[0] = new Wow();
quizBank[0].question = "my adddtional question";
quizBank[0].answer = "adtinal question answer here";

please check it once

let me know the status

happy coding

Edited 3 Years Ago by radhakrishna.p: giving clarity on the solution

in addition to that please remove '%n' and replace it with '\n'

note : i dont know exactly if you are using %n for any special reason (leave it as it is if there is no special reason)

System.out.printf("%d. %s?%n", number, quizBank[number].question);

let me know the status

Edited 3 Years Ago by radhakrishna.p: giving clarity on the solution

I think that using %n instead of \n is more OS-friendly. As \n specifies a newline character that some operating systems don't have, whereas %n uses the local OS newline character

This article has been dead for over six months. Start a new discussion instead.