mardi 28 avril 2020

Is there any mistake in my condition statement? [closed]

These are my snipped code below. When i input 2, which is the feline type, it was supposed to either output Feline doesnt want to roam at all today if the feli is 0 or Roaming for total range of 0 in 12 minutes if the feli is not 0. But, in my output which i attached the picture below, it also prints the roaming for total range of 0 in 12 even if the feli is zero. Is there any mistake on my condition statement? Any help is appreciated. Thank you.

void take(){
        int choose;
        int roam;
        int roaming;
        int p = anm.nama.size();
        if(p==0){
            view();
        }
        else{
            view();

            do{
                System.out.print("Choose animal to take for a stroll [1 - " + p+ "]: ");
                choose = scan.nextInt();
            }while(choose<1||choose>p);

            do{
                System.out.print("Roaming time [0-50]: ");
                roam = scan.nextInt();
            }while(roam < 0 || roam > 50 );

            if(roam==0)roaming = 60;
            else roaming = roam;

            for(int i=0; i<anm.nama.size(); i++){
                if(fel.genuss.get(i).equals("feline")){
                    int batas = 2;
                    Random rand = new Random();
                    int feli = rand.nextInt(batas);

                    if(feli == 0){
                        System.out.println("Feline doesn't feel like roaming at all today..");
                        break;
                    }
                    else{
                        int duration = 0;
                        if(roaming == 30)
                            {
                            duration = 30;
                            System.out.println("Roaming for total range of " + anm.range() +" in " + duration +" minutes");
                            }
                        else System.out.println("Roaming for total range of " + anm.range() +" in " + duration +" minutes");
                        break;
                    }
                }


                else if(can.genuss.get(i).equals("canine")){
                    int duration = 0;
                    if(roaming==0)
                        {
                        duration = 60;
                        anm.range();
                        System.out.println("Roaming for total range of " + can.range() +" in " + duration +" minutes");
                        }
                    else duration = roaming;
                    anm.range();
                    System.out.println("Roaming for total range of " + can.range() +" in " + duration +" minutes");
                }
            }
        }


    }

This is my output

Aucun commentaire:

Enregistrer un commentaire