What's new

Java Programming, pa tulong!!!

Nero Swallowtail

Eternal Poster
Joined
Aug 13, 2020
Posts
465
Reaction
174
Points
280
guys my problema yung code ko, ganto dapat yung magiging output nya, kapag tama ung sagot na ininput ni user dapat mag cocontinue yung program sa next question kaso di ko alam kung ano ung ibabato kong condition para yun ung mag execute, next is kapag mali ung ininput na sagot ni user, my three tries sya so bale ang iniisip ko is need ng loop every question(not sure kung ganon yung tama pero un ung ginagawa ko) ang problema nung program ko is, kapag nag resort sya sa else ay ine execute nya yung loop sa ibaba
java.png

parang ganto po, gusto ko sana yung loop lang nung specific question ang uulitin or ewan baka my mali lang talaga sa ginagawa ko hehe, kung meron man paki correct po ako kung ano ang tama, and yes oo napansin ko ung mali sa tanong muzzle pala dapat yan di compensator HAHAHAHAH, isa pa po, array po ang ginagamit ko para don sa questions, so dun sa if statements ang una kong triny is, if(userinput.equalsIgnoreCase(c.choices[1])) eh ayaw kase number yung na de detect ni java, kaya gumawa nalang ako ng ibang class para dun sa letters, pa help po plss kung pano to aayusin, need pa kase lagyan nito ng try catch block at user defined exception
baka nalilito na kayo sa caption ko kaya i eespecify ko ang aking mga katanugan HAHAHAHA need ko lang ng help about dun sa looping kase nga need ng program mag proceed sa next question kapag tama yung user input e kaso inuulit nya lang yung tanong sa loop kahit na tama yung user input, pag sa else naman sya nag resort ineexecute nya kahit na yung code sa baba, ilang araw nakong stuck dito, lasyt na to, gusto ko sanang ma enjoy yung bakasyon ko kaso di ko matapos HAHAHAHA
eto yung code

You do not have permission to view the full content of this post. Log in or register now.
code nung mga class

You do not have permission to view the full content of this post. Log in or register now.
 

Attachments

[CODE lang="java" title="Working Code"]import java.util.*;

public class Beta extends Exception{

public static void main(String[] args) {

String UserAns;
int n = 0, tries = 3;

Scanner scan = new Scanner(System.in);

Questions q = new Questions();
Choices c = new Choices();
Prompt p = new Prompt();
CorrectAns a = new CorrectAns();

System.out.println("Quiz Bee!");



while(n <= q.questions.length-1) {
System.out.println(q.questions[n]);
System.out.println(c.choices[0]);
System.out.print(p.AnsPrompt[0]);
UserAns = scan.nextLine();


if(UserAns.equalsIgnoreCase(a.CorrectAns[n])) {

System.out.println("Tama ka");

n++;
continue;

}

else{

System.out.println("You're Wrong!");
System.out.println((--tries) + " attempt(s) left");
if(tries == 0) {
System.out.println("No remaining tries");
break;
}
else
{
System.out.println("Next Question");
continue;
}
}

}
System.out.println("No Question available");
}

public static class Questions {

String questions [] = {"1. What is the BEST Muzzle for Assault ***** when controling your recoil?","2. Sample Question 2?"};

}


public static class Choices {
String [] choices = {"a. Suppresor \nb. Compensator \nc. Flash Hider","a. Suppresor2 \nb. Compensator2 \nc. Flash Hider2"};


}


public static class Prompt {
String AnsPrompt [] = {"Enter your Response here: "};

}


public static class CorrectAns {
String CorrectAns [] = {"b","c"};

}
}

[/CODE]
 
try mo
Java:
import java.util.*;

public class Beta extends Exception{
    
    
    public static void main(String[] args) {
    
    Scanner input = new Scanner(System.in);
    
    String answer = "b";
    String prompt = "Enter your Response here: ";
    String [] choices = {"a. Suppresor \nb. Compensator \nc. Flash Hider"};
    String [] questions  = {"1. What is the BEST Muzzle for Assault ***** when controling your recoil?","Yes or NO?","No or Yes?"};
    //nag add another question para ma test
    
    String user;
    
    int n = 0;
    int tries = 3;


    System.out.println("Quiz Bee!");

    
    //Pointer sa next index sa questions
     
     
    int index = 0;
    
    //kapag na ubos na yung tries ma stop na ang loop or kapag ang n ay mataas na sa 3.
    //bakit n?
    
    while(n <= 3 && tries > 0) {
    
        System.out.println(questions[index]);
        System.out.println(choices[0]);
        System.out.print(prompt);
    
        user = input.nextLine();

    
        if(user.equalsIgnoreCase(answer)) {

            System.out.println("Tama ka");
            index++;
            
            //so pagtama increment index para magpoint sa second question
            //gawa ka condition para hindi mag out of bounce young index sa size ng question array
            
        }else{
            
            System.out.println("You're Wrong!");
            System.out.println((--tries) + " attempt(s) left");
            
            //so pag mali hindi tayo mag increment ng index para same question parin
            continue;
                
        }
        
        System.out.println ("Next Question");
        n++;
        
    }


    }
}
 

Similar threads

Back
Top