Loyola College in Maryland

CS 201 - Computer Science I
Spring 2009


Loyola College > Department of Computer Science > Dr. James Glenn > CS 201 > Homework > Quiz #3 Practice

Solutions will be available later.

Problem 0: Review old homeworks and labs.

Problem 1: Create an applet that displays the following picture. This applet is 200 pixels wide and 200 pixels high. The blue frame is 200x100. The circle is 80 pixels in diameter. Everything is centered.

Problem 2: Express each of the following as a Boolean expression in Java. Assume a, b, c, x, and y have been declared as ints and s has been declared as a String.

Problem 3: For each of the System.out.println statements below, give a pair of values for x and y that will cause the statement to be executed, or write ``impossible'' if a particular statement cannot be reached.

int x =        ;
int y =        ;

if (x > 2)
{
  if (y < 5)
  {
    System.out.println("Case 1");
  }
  else
  {
    System.out.println("Case 2");
  }
}
else if (y < 10)
{
  if (x > 4)
  {
    System.out.println("Case 3");
  }
  else
  {
    System.out.println("Case 4");
  }
}
else
{
  System.out.println("Case 5");
}

Problem 4: Complete the following code fragment so that it outputs (using System.out.println) the value of 3 * x if x is not more than 10 and the value of 1 - x otherwise.

Scanner scan = new Scanner(System.in);
System.out.println("Enter a number:");
double x = scan.nextDouble();

Valid HTML 4.01 Transitional