Assignemnt #31

Code

  /// Name: Sam Wilson
  /// Period: 6
  /// Program Name: elseandif
  /// File Name: elseandif.java
  /// Date Finished: 10/8/2015
 
 

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


            //If and else allow the code to determine if the statement is true to print one things and if it is false to print another, if the code has no answer then else is what's printed because it's creating a second statement that is indivual and not true.
            
            //removing else causes the code to print both ifs.
    
    		if ( cars > people )
    		{
    			System.out.println( "We should take the cars." );
    		}
    		else 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 31