Pre-Lab Assignment: Lab 6      Name ___________________________________

  1. Rewrite the following cascading if statement to a switch statement.
    System.out.println("Enter size box you want");
    int boxSize = scan.nextInt();
    double price;
    if (boxSize == 10)
    {
       System.out.println("Small");
       price = 2.5;
    }
    else if (boxSize == 20) 
    {
       System.out.println("Medium");     
       price = 3.75;
    }
    else if (boxSize == 30)
    {
       System.out.println("Large");
       price = 5.0;
    }
    else
    {
       System.out.println ("Not a valid size.");
       price = -1;
    }
    
    

  2. Fix the following code fragment.
    if(total == MAX)
    	if(total < sum)
    		System.out.println("total == MAX and sum total < sum");
    else
    	System.out.println("total is not equal to MAX");
    
    
    
    

  3. Rewrite each condition below in valid Java syntax (give a boolean expression):
    1. x > y > z

       

       

    2. neither x nor y is equal to 0

       

       

    3. both x and y are equal to 0

       

       

    4. x is greater than y but less than z

       

       

     

  4. Use the laws of logic to write a Java expression equivalent to the following without using the not (!) operator.
              ! (age >= 65 && income < 20000)
    
    
    
    
    
    
  5. Use truth tables to determine whether each pair of expressions is equivalent.
    1. NOT q OR p
      p OR NOT(q OR p)
      
      
      
      
      
      
      
      
      
      
      
      
      

    2. (p AND r) OR (q AND NOT r)
      (p AND q AND NOT r)