Assignment # 35 and Else and If

Code

    /// Name: Tommy Oyuntseren
    /// Period: 7
    /// Program Name: ElseAndIf
    /// File Name: ElseAndIf.java
    /// Date: 10/22/2015

 public class ElseAndIf
{
	public static void main( String[] args )
	{
		int people = 30;
		int cars = 40;
		int buses = 15;

        //ELSE performs a command that comes afer it, if boolean statement inside braces afer IF is false.
        //ELSE IF is not a separate command, but an IF that comes after ELSE, making it the next command.
        
        
        // The only difference is a minor waste of computer resources, because 
        // the machine has to check both of the IF statements, if cars < people, whereas with IF ELSE
        // it will only check one if cars > people
        // Also now it will print out "We can't decide." when cars >= people, while with ELSE IF
        // it would print it only if cars = people
		if ( cars > people )
		{
			System.out.println( "We should take the cars." );
		}
		if ( cars < people )
		{
			System.out.println( "We should not take the cars." );
		}
		else
		{
			System.out.println( "We can't decide." );
		}


		if ( buses > cars )
		{
			System.out.println( "That's too many buses." );
		}
		else if ( buses < cars )
		{
			System.out.println( "Maybe we could take the buses." );
		}
		else
		{
			System.out.println( "We still can't decide." );
		}


		if ( people > buses )
		{
			System.out.println( "All right, let's just take the buses." );
		}
		else
		{
			System.out.println( "Fine, let's stay home then." );
		}

	}
}
   
  

Picture of the output

Assignment 35