• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

Java - question

Initiate Mage
Joined
Aug 22, 2013
Messages
1
Reaction score
0
hi,

i started college a few weeks ago, and it includes java, and i've got a question, i hope someone is able to help me.

Code:
public class oef8 {

    public static void main(String[] args) {
    
        String seizoen, code;
        int aantalN,ster;
        double prijs;


        ster = Invoer.leesInt("give the amount of stars");
        seizoen = Invoer.leesString("give in the season");
        code = Invoer.leesString("give the code");
        aantalN = Invoer.leesInt("amount of nights");
        
        [B][COLOR=#ff0000]if[/COLOR][COLOR=#ff0000](code.equals("A")){
            prijs = aantalN * 80;
        }
        
            else if(ster == 1){
                    prijs = 30;
            }          
                 else if(ster <= 3){
                          prijs = 40;
                        }
                        else prijs = 55;[/COLOR][/B][COLOR=#ff0000]
                 [/COLOR]
        
                      
        if(code.equals("O")){
            prijs = prijs *1.2;
        }    
            else if(code.equalsIgnoreCase("H")){
                     prijs = prijs * 1.5;
                  }
                     else prijs = prijs * 1.6;




                        
                      
        if(seizoen.equals("L") && (code.equals("O") || code.equals("H"))){
            prijs = prijs * 0.9;
        }
        
        prijs = prijs * aantalN;


        System.out.println("de prijs is" + prijs);
        
            
    
        
        
    }
}


my question is something with the brackets, if the code = A it will run the whole progam? i mean with that will the program check if the code = O and so on? my teacher asked if the code equals to A it doesn't have to run the rest of the program because the price is already known,

so that's the question ; are the brackets placed correctly so it will run only the red marked code if code = A

i hope someone is able to help me, thanks in advance.
 
That one pokemon thing
Loyal Member
Joined
Apr 3, 2010
Messages
1,766
Reaction score
621
You could either return the entire method, or place it like:
PHP:
if(code.equals("A") {
//Only part A
} else {
//The rest of the code.
}

That way it will only execute whatever's placed within the conditional statement A.
 
Back
Top