Quiz 3 Solution

  1. Terms and Concepts

    1. F
    2. T
    3. T
    4. F

  2. Boolean Expressions
    ( ( year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0 )	
    
  3. Code Tracing
    Line 2
    Line 3
    
  4. Code Tracing
    Inside: x = 6, y = 2
    Inside: x = 6, y = 9
    Outside: x = 3, y = 8
    
  5. Java Class
    class Apartment {
    	private int bedrooms;
    	private double rent;
    
    	public Apartment(int rooms, double amount) {
    		if (rooms < 0)
    			rooms = 0;
    		if (amount < 0)
    			amount = 0;
    		bedrooms = rooms;
    		rent = amount;
    	}
    
    	public int getNumberofBedrooms() {
    		return bedrooms;
    	}
    
    	public double getRent() {
    		return rent;
    	}
    
    	public void raiseRent(double amount) {
    		if (amount < 0)
    			amount = 0;
    		rent += amount;
    	}
    
    	public boolean isEfficiency() {
    		return (bedrooms == 0);
    	}
    
    	public boolean isExpensive() {
    		return (rent > 400 + 150 * bedrooms);
    	}
    }