🔒 Closed Pahelp mga master

Status
Not open for further replies.

Kiss21

Eternal Poster
pano sir ma call yung q1e() (yung my white circle) gamit yung Switch statement(red circle)?
bali po kapag nag output na po yung number the mag cacall po siya sa quiestion()

example: case 1: 1 then call q1e();

bale po mag rarandom kasi sir yung number 1-15. then each number ay my naka assign na question. pero di ako marunong kun pano mag call nang question na naka assign per number. hehe

pano po yan di ko po mafix e hehe sana po matulongan nyo po ako :(
than you po mga master :)
 

Attachments

  • random.png
    random.png
    39.5 KB · Views: 0
Ang gusto mo nakaassign na number sa question ? Pwede mo ideclare yung variable ni qe1 or use if else
 
mahirap pag sinasabi lang namin dito baka kasi dimo rin lang magets at i code.Try ka muna hanap ng source code sa google
 
mahirap pag sinasabi lang namin dito baka kasi dimo rin lang magets at i code.Try ka muna hanap ng source code sa google
nagets ko an sir pero ang prblem ko namn po ay yung repetition of number or repetion of question sir. any suggention po
 
Kung sa repetition ang gagawin mo jan ay pag nasagutan na di na pwede uitin at kung hindi pa yun ang uulit
 
kung tatawagin lang po yung method. Ang gagamitin po ay yung kanyang method name na 'q1e()' sa loob nung case 1
Code:
int main()
{
    int total_number = 15;
    int first_number = 1;
    int RandomNum = rand() % total_number + 1;
    for (int a = 0; a<1; a++) {
        RandomNum = rand() % total_number + 1;
        cout << RandomNum << endl;
        switch (a) {
        case 1: {
            q1e();
        }
        case 2: {
            //question 2
        }
        case 3: {
            //question 3
        }
        }
    }
}
 
gumamit ka ng MAP array.
- key-value pair siya...(int, string)

tapos gawa ka ng MAP array (
Code:
questions_map
(
1, "What is the shape of the moon?",
2, "How many stars in the sky?",
3, "What is the square root of 33,333?",
4, "Who is the Bruce Lee?"
}


tapos gawa ka ng blank array na pag iipunan mo ng nasagutan ng
Code:
answered[] array
- ang laman later ay
{1, 4, 5.......}


Tapos ito na yung pseudo code
1) generate a random integer and save it to KEY variable
2) if KEY IS NOT in the ANSWERED_ARRAY go to step 3.....else.....go to step 1
3) get the question from QUESTIONS_MAP using the KEY....and...store KEY at ANSWERED_ARRAY
 
gumamit ka ng MAP array.
- key-value pair siya...(int, string)

tapos gawa ka ng MAP array (
Code:
questions_map
(
1, "What is the shape of the moon?",
2, "How many stars in the sky?",
3, "What is the square root of 33,333?",
4, "Who is the Bruce Lee?"
}


tapos gawa ka ng blank array na pag iipunan mo ng nasagutan ng
Code:
answered[] array
- ang laman later ay
{1, 4, 5.......}


Tapos ito na yung pseudo code
1) generate a random integer and save it to KEY variable
2) if KEY IS NOT in the ANSWERED_ARRAY go to step 3.....else.....go to step 1
3) get the question from QUESTIONS_MAP using the KEY....and...store KEY at ANSWERED_ARRAY
Sir Cody Ganito po ba Tapus po? Medyo na guluhan ako sa 2 saka 3.

Code:
public class HashMapTesting
{
    static HashMap<Integer, String> questionMap = new HashMap<Integer, String>();
    static String answerArray [];
    static Random random = new Random();
    static int randomNumber;
    static Scanner userInput = new Scanner(System.in);
    static int numbers;
   
    public static void main (String [] args){
       
        questionsMap();
        pagiipinunangmganasagutanan();
        user();
       
    }
   
    static void questionsMap(){
       
        questionMap.put(1, "What is the shape of the moon?");
        questionMap.put(2, "How many stars in the sky?");
        questionMap.put(3, "What is the square root of 33,333?");
        questionMap.put(4, "Who is Bruce Lee?");
    }
   
    static void pagiipinunangmganasagutanan(){
        answerArray = new String [4];
        answerArray[0] = "oblate spheroid";
        answerArray[1] = "100 thousans million";
        answerArray[2] = "3";
        answerArray[3] = "martial artist";
      }  
    }
 
good job, man. tama, you are on the right track.
konting adjustment pa. I think meron ka ng idea kaya bibigyan na kita ng working code.
baka hindi exact sa gusto mo kaya i-adjust mo na lang. AND most important, pag-aralan mo.

Code:
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;

public class MainApp {
    static Map<Integer,String> questionsMap;
    static Map<Integer,String> answeredMap;
    static Random random;
    static Scanner userAnswer;
  
    public static void main(String[] args) {
        //1. load the questions
        loadQuestions();
      
        //2. initialize the answeredMap container (walang laman muna, standby lang)
        initializeAnsweredMap();
      
        //3. initialize random int maker
        initializeRandomNumberMaker();
      
        //4. initialize scanner for user input
        initializeScanerForUserInput();
      
        //5. itong unang or outer WHILE na ito, siguraduhin lang na hindi pa ubos ang mga QUESTIONS
        //tapos pag ubos na ang questions, e-exit na yung APP
        while(questionsMap.size() != answeredMap.size()) {
          
            //5A. habang may questions pa, ito ang gagawin niya (this is the INNER WHILE)
            int key = 0;
            //dahil gusto natin huwag umulit yung questions, dapat mag generate na key
            //na wala pa sa answeredMap
            while(answeredMap.containsKey(key) || key==0) {
                key = random.nextInt(questionsMap.size()) + 1;
            }
          
            //5B.pag wala pa yung key sa answeredMap, gagamitin na natin yung key
            //na pagkuha ng questions, ganito, tapos display kaagad yung question:
            System.out.print(questionsMap.get(key));
          
            //5C.hintayin yung answer ng user
            String answer = userAnswer.next();
          
            //5D. tapos pag may sagot na, ilalagay natin yung KEY at SAGOT sa answeredMAP
            answeredMap.put(key, answer);
          
        }//end ng unang WHILE or outer WHILE
      
        //6. message lang ito pag ubos na yung mga questions
        System.out.println("\n**********************\nWala na. Ubos na mga questions.");
        //7. Dito puwede mo na lagyan ng features kagaya ng kung ilan ang mali at ilan ang tama
        //o at saka i-display mo yung mga sagot, etc etc etc.

    }
  
    static void loadQuestions() {
        //initialize bago gamitin
        questionsMap = new HashMap<>();
      
        //simulan ng lagyan ng mga questions (as many as you want)
        questionsMap.put(1, "What is the shape of the moon?");
        questionsMap.put(2, "How many stars in the sky?");
        questionsMap.put(3, "What is the square root of 33,333?");
        questionsMap.put(4, "What is Bruce Lee good at?");
        questionsMap.put(5, "Who is the President of Haiti?");
        questionsMap.put(6, "Who inveted the microscope?");
        questionsMap.put(7, "Name the colors of Russian flag?");
        questionsMap.put(8, "Seven times seven divided 3 plus 1 is?");
        questionsMap.put(9, "What is the 50th element in the periodic table?");
        questionsMap.put(10, "Who came first, chicken or egg?");
    }
  
    static void initializeAnsweredMap() {
        answeredMap = new HashMap<>();
    }
  
    static void initializeRandomNumberMaker() {
        random = new Random();
    }
  
    static void initializeScanerForUserInput() {
        userAnswer = new Scanner(System.in);
    }


}
Sir Heto Po Yung Panibagong Gawa ko Hindi ko Alam kung Tama.
Code:
public class AnotherSample2D
{
    static HashMap<Integer, String> map;
    static HashMap<Integer, String> answerMap;
    static Random random;
   
    public static void main(String [] args){
       
        init();
        displayWelcome();
        listOfQuestion();
        answerArray();
       
    }
   
    static void init(){
        map = new HashMap<>();
        answerMap = new HashMap<>();
        random = new Random();
    }
   
    static void displayWelcome(){
        System.out.println("This Is A Testing I am newbie");
    }
   
    static void listOfQuestion(){
        map.put(1, "What is the shape of the moon?");
        map.put(2, "How many stars in the sky?");
        map.put(3, "What is the square root of 33,333?");
        map.put(4, "Who is Bruce Lee?");
    }
   
    static void answerArray(){
        answerMap.put(1, "oblate spheroid");
        answerMap.put(2, "100 thousans million");
        answerMap.put(3, "182.57");
        answerMap.put(4, "Martial Artist");
    }
   
}
pano ko icocopare sir yung sa while loop kasi pag nilalagay ko yung answerd mapy error. Sir wag nyo po ibigay yung code gusto ko kasi matuto. Hayaan nyo mag isip po muna ako.
 
Sir Heto Po Yung Panibagong Gawa ko Hindi ko Alam kung Tama.

ok, tama.
pero konti pa.

1 - so meron ka MAP para sa question (it loads sa umpisa ng app)..good
2 - meron ka ng rin MAP pa sa mga correct na sagot (it loads sa umpisa ng app)..good
3 - kailangan mo ng isa pang MAP para lalagyan ng mga nasagutan ng questions at sagot ng user <Integer, String>

4 - tapos bago mag umpisa yung questions....i-check mo kung pareho yung SIZE() ng questionsMap at nasagutanNgMap...kung pareho ang size, ubos na ang questions. Exit na nag ang program (gamit ka ng WHILE LOOP)

5. pag hindi pa ubos ang questions
- generate key (tapos check kung ang key ay wala pa sa nasagutanNgMap)
- pag nasa nasagutanNGMap...generate uli
- pag ang key wala pa sa nasagutangNgMap, then get question from questionsMap
 
6. pag nag enter ng sagot ang user:
- then store the KEY and SAGOT sa nasagutanNgMap....parang ganito nasagutangNgMap.put(key, sagot)
- tapos start comparing na sagot vs yung mga sagot sa answerMap mo
----using the key, get the correct answer from answerMap
----then compare the user-sagot doon sa makukuha mong answer sa answerMap..
----------------user "sagot.equals(answerMap sagot"
----------------at saka baka kailangan mo ng trim()..... at saka toLowerCase()... etc etc... para ma "sanitize" muna ang mga string para siguradung wala mga spaces at extra strings....
---then make score, etc etc etc.
 
6. pag nag enter ng sagot ang user:
- then store the KEY and SAGOT sa nasagutanNgMap....parang ganito nasagutangNgMap.put(key, sagot)
- tapos start comparing na sagot vs yung mga sagot sa answerMap mo
----using the key, get the correct answer from answerMap
----then compare the user-sagot doon sa makukuha mong answer sa answerMap..
----------------user "sagot.equals(answerMap sagot"
----------------at saka baka kailangan mo ng trim()..... at saka toLowerCase()... etc etc... para ma "sanitize" muna ang mga string para siguradung wala mga spaces at extra strings....
---then make score, etc etc etc.
Sir salamat naiiyak ako sa sarili ko ganun ako ka hina.
 
Sir salamat naiiyak ako sa sarili ko ganun ako ka hina.
hehehe.... galing din ako dyan, man.
sinasabunutan ko rin ang buhok ko noon.
pero noong nakuha ko na at medyo lumiliwanag na ang lahat sa akin... nag painom ako sa barangay namin sa tuwa ko... lol
 
hehehe.... galing din ako dyan, man.
sinasabunutan ko rin ang buhok ko noon.
pero noong nakuha ko na at medyo lumiliwanag na ang lahat sa akin... nag painom ako sa barangay namin sa tuwa ko... lol
Sir pasensya na pala sa abala oo nga sarap uminom lalo na pag naka pag pasa ka ng activity sa school. Shot nlng Tayo Sir hahaha
 
Pinag iisapan ko pa kaya nakita ko nlng my sagot na pala.
huwag mong titigan ang code mo sa computer monitor.
ipikit mo ang mga mata tapos isipin mo yung STEP by STEP logic...parang sa totoong buhay lang yan.
(effective ang technique na ito sa akin noon).... tapos drawing... sketch.... parang strategy ni coach sa basketball.. :)
 
Status
Not open for further replies.

About this Thread

  • 18
    Replies
  • 1K
    Views
  • 6
    Participants
Last reply from:
Donqexote

Trending Topics

Online now

Members online
819
Guests online
660
Total visitors
1,479

Forum statistics

Threads
2,279,442
Posts
28,990,737
Members
1,225,914
Latest member
joh62
Back
Top