Share on Google+Share on Google+

Darren Aquilina
Java Variables Help Please!
0 Answer(s)      5 years ago
Posted in : Java Beginners

Hi, I just started with java and i need help with my school project, this is it so far:

import java.util.*;

public class ProjectCS {

public static void main(String[] args) {

    welcome();
    menu();
}
public static void welcome()
    {
    System.out.println("+------------------+");
    System.out.println("¦_-¯-_Welcome!_-¯-_¦");
    System.out.println("¦¯-_-¯Welcome!¯-_-¯¦");
    System.out.println("+------------------+");
    try
    {
    Thread.sleep(2500);
    }
    catch(InterruptedException e)
    {
    System.out.println(e.getStackTrace());
    }

    } //end of class welcome

public static void menu() {
    int choice;

    do{
    System.out.println("\t...Menu...");
    System.out.println("1. Math Quiz");
    System.out.println("2. Computer Quiz");
    System.out.println("3. English Quiz");
    System.out.println("4. Random Quiz");
    System.out.println("5. Exit");
    System.out.print("Choice: ");
    choice = Keyboard.readInt();
    System.out.print("--------------------");

    switch (choice) {
        case 1: mtdmathquiz();
                break;
        case 2: mtdcompquiz();
                break;
        case 3: mtdengquiz();
                break;
        case 4: mtdranquiz();
                break;
    } //end of switch

    }while (choice < 5);
    System.out.println("--------------------");
    System.out.println("\t\t\tExit Was Chosen!");

    try
    {
    Thread.sleep(1000);
    }
    catch(InterruptedException e)
    {
    System.out.println(e.getStackTrace());
    }
    System.out.println("\t\t\t\tGoodbye!\n");
    try
    {
    Thread.sleep(1500);
    }
    catch(InterruptedException e)
    {
    System.out.println(e.getStackTrace());
    }
    System.out.println("\t\t+------------------------+");
    System.out.println("\t\t¦ Name : Darren Aquilina ¦");
    System.out.println("\t\t¦ Class: 4.2 Option: 2   ¦");
    System.out.println("\t\t+------------------------+");

} //end of class menu

public static void mtdmathquiz() {
System.out.println("\nMath Quiz was chosen.");
    int mathans1, mathans2, mathans3, mathans4;
    int mathcount = 0;

    System.out.println("1. What is 123 × 23");
    System.out.println("1: 1968");
    System.out.println("2: 2460");
    System.out.println("3: 2829");
    System.out.println("4: 3075");
    System.out.print("Answer(1-4): ");
    mathans1 = Keyboard.readInt();

    if(mathans1 == 3){
        System.out.println("Correct!");
        mathcount = mathcount + 1;
    }else{
        System.out.println("Wrong!");
    }

    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + mathcount);
    System.out.println("--------------------");

    System.out.println("2. What is 510 × 7");
    System.out.println("1: 4080");
    System.out.println("2: 3570");
    System.out.println("3: 3640");
    System.out.println("4: 2550");
    System.out.print("Answer(1-4): ");
    mathans2 = Keyboard.readInt();

    if(mathans2 == 2){
        System.out.println("Correct!");
        mathcount = mathcount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + mathcount);
    System.out.println("--------------------");

    System.out.println("3. What is The Square Root of 1521?");
    System.out.println("1: 31");
    System.out.println("2: 33");
    System.out.println("3: 37");
    System.out.println("4: 39");
    System.out.print("Answer(1-4): ");
    mathans3 = Keyboard.readInt();

    if(mathans3 == 4){
        System.out.println("Correct!");
        mathcount = mathcount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + mathcount);
    System.out.println("--------------------");

    System.out.println("4. What is 843 ÷ 6?");
    System.out.println("1: 140.5");
    System.out.println("2: 150.5");
    System.out.println("3: 123");
    System.out.println("4: 348");
    System.out.print("Answer(1-4): ");
    mathans4 = Keyboard.readInt();

    if(mathans4 == 1){
        System.out.println("Correct!");
        mathcount = mathcount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.print("Your Final Score is: " + mathcount);
    System.out.println("/4");

    if(mathcount >= 2)
            {
            System.out.println("You Passed!");
            }else
            {
            System.out.println("You Failed!");
            }

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

public static void mtdcompquiz() {
    System.out.println("Computer Quiz was chosen.");
    int compans1, compans2, compans3, compans4;
    int compcount = 0;

    System.out.println("1. Which is the correct Decimal of 01110011?");
    System.out.println("1: 117");
    System.out.println("2: 115");
    System.out.println("3: 120");
    System.out.println("4: 111");
    System.out.print("Answer(1-4): ");
    compans1 = Keyboard.readInt();

    if(compans1 == 2){
        System.out.println("Correct!");
        compcount = compcount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + compcount);
    System.out.println("--------------------");

    System.out.println("2.From The Question above, What is the ASCII code of the correct answer?");
    System.out.println("1: s");
    System.out.println("2: u");
    System.out.println("3: x");
    System.out.println("4: o");
    System.out.print("Answer(1-4): ");
    compans2 = Keyboard.readInt();

    if(compans2 == 1){
        System.out.println("Correct!");
        compcount = compcount + 1;;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + compcount);
    System.out.println("--------------------");

    System.out.println("3. What does RAM stand for?");
    System.out.println("1: Read Access Memory");
    System.out.println("2: Random Available Memory");
    System.out.println("3: Random Access Memory");
    System.out.println("4: Read After Morning");
    System.out.print("Answer(1-4): ");
    compans3 = Keyboard.readInt();

    if(compans3 == 3){
        System.out.println("Correct!");
        compcount = compcount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + compcount);
    System.out.println("--------------------");

    System.out.println("4. What Does GUI stand for?");
    System.out.println("1: Grand User Interface");
    System.out.println("2: Great User International");
    System.out.println("3: Genius User International");
    System.out.println("4: Graphic User Interface");
    System.out.print("Answer(1-4): ");
    compans4 = Keyboard.readInt();

    if(compans4 == 4){
        System.out.println("Correct!");
        compcount = compcount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.print("Your Final Score is: " + compcount);
    System.out.println("/4");
                if(compcount >= 2)
                {
                System.out.println("You Passed!");
                }else
                {
                System.out.println("You Failed!");
                }

    System.out.println("--------------------");


}

public static void mtdengquiz() {
    System.out.println("English Quiz was chosen.");
    int engans1, engans2, engans3, engans4;
    int engcount = 0;

    System.out.println("1. What is the past tense of GO?");
    System.out.println("1: GOED");
    System.out.println("2: GO");
    System.out.println("3: WILL GO");
    System.out.println("4: WENT");
    System.out.print("Answer(1-4): ");
    engans1 = Keyboard.readInt();

    if(engans1 == 4){
        System.out.println("Correct!");
        engcount = engcount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + engcount);
    System.out.println("--------------------");

    System.out.println("2. Who wrote 'The Merchant of Venice'?");
    System.out.println("1: William Shakespear");
    System.out.println("2: Albert Einstein");
    System.out.println("3: Roald Dahl");
    System.out.println("4: Barry Hines");
    System.out.print("Answer(1-4): ");
    engans2 = Keyboard.readInt();

    if(engans2 == 1){
        System.out.println("Correct!");
        engcount = engcount + 1;;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + engcount);
    System.out.println("--------------------");

    System.out.println("3. What is Personification?");
    System.out.println("1: 'The Person Sneezed'");
    System.out.println("2: 'The Tree Cried'");
    System.out.println("3: 'The Dog Barked'");
    System.out.println("4: 'The Fish Died'");
    System.out.print("Answer(1-4): ");
    engans3 = Keyboard.readInt();

    if(engans3 == 2){
        System.out.println("Correct!");
        engcount = engcount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + engcount);
    System.out.println("--------------------");

    System.out.println("4. What is Sarcasm");
    System.out.println("1: When a person says the Truth.");
    System.out.println("2: When a person says a Lie.");
    System.out.println("3: When a person says something but is really the Opposite of it.");
    System.out.println("4: When a person says something which is Confusing.");
    System.out.print("Answer(1-4): ");
    engans4 = Keyboard.readInt();

    if(engans4 == 3){
        System.out.println("Correct!");
        engcount = engcount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.print("Your Final Score is: " + engcount);
    System.out.println("/4");
                if(engcount >= 2)
                {
                System.out.println("You Passed!");
                }else
                {
                System.out.println("You Failed!");
                }

    System.out.println("--------------------");


}

public static void mtdranquiz() {
    System.out.println("Random Quiz was chosen.");
    int ranans1, ranans2, ranans3, ranans4;
    int rancount = 0;

    System.out.println("1. What does 'Gws' Stand for?");
    System.out.println("1: Goal well saved");
    System.out.println("2: Good word said");
    System.out.println("3: Get well soon");
    System.out.println("4: Great world saver");
    System.out.print("Answer(1-4): ");
    ranans1 = Keyboard.readInt();

    if(ranans1 == 3){
        System.out.println("Correct!");
        rancount = rancount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + rancount);
    System.out.println("--------------------");

    System.out.println("2. Which of these is not an online multiplayer game?");
    System.out.println("1: World of Warcraft");
    System.out.println("2: Gravity Man");
    System.out.println("3: Minecraft");
    System.out.println("4: Runescape");
    System.out.print("Answer(1-4): ");
    ranans2 = Keyboard.readInt();

    if(ranans2 == 2){
        System.out.println("Correct!");
        rancount = rancount + 1;;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + rancount);
    System.out.println("--------------------");

    System.out.println("3. What are mouse keys?");
    System.out.println("1: The pendrive used when connecting a wireless mouse");
    System.out.println("2: A type of keylogger");
    System.out.println("3: A method to control your keyboard with your mouse");
    System.out.println("4: A method to control your mouse with your keyboard");
    System.out.print("Answer(1-4): ");
    ranans3 = Keyboard.readInt();

    if(ranans3 == 4){
        System.out.println("Correct!");
        rancount = rancount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.println("Your Current Score is: " + rancount);
    System.out.println("--------------------");

    System.out.println("4. What is a Graphics Card?");
    System.out.println("1: A card for you to insert in your computer so you can see and have better Graphics");
    System.out.println("2: An access card in a place where people do Graphical Communication");
    System.out.println("3: A Gift Card for a Game called 'Graphics'");
    System.out.println("4: None of the above");
    System.out.print("Answer(1-4): ");
    ranans4 = Keyboard.readInt();

    if(ranans4 == 1){
        System.out.println("Correct!");
        rancount = rancount + 1;
    }else{
        System.out.println("Wrong!");
    }
    System.out.println("--------------------");
    System.out.print("Your Final Score is: " + rancount);
    System.out.println("/4");
                if(rancount >= 2)
                {
                System.out.println("You Passed!");
                }else
                {
                System.out.println("You Failed!");
                }

    System.out.println("--------------------");


}

}

and i would like to get the some integers from the mtdmathquiz(); , mtdcompquiz(); , mtdengquiz(); , mtdranquiz(); to menu();. The integers/variables that i want to be able to use are: mathcount, compcount, engcount and rancount. PLEASE HELP!

Ads

View Answers









Related Tutorials/Questions & Answers:
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads