3.3 Solutions

    1.  
      void setup()
      {
         final int VOTING_AGE = 18;
         int age;
         boolean eligible;
         age = getInt("Enter age");
         if (age >= VOTING_AGE)
            eligible = true;
         else
            eligible = false;
         if (eligible)
            println("Eligible to vote");
         else
            println("Not eligible to vote");
      } 
    2. Eligible to vote
    3. eligible = age >= VOTING_AGE;
    1. if (total == 0)
         zeroCount++;
    2. if (n == (int)sqrt(n) * (int)sqrt(n))
         println(n + " is a perfect square");
      else
         println(n + " is NOT perfect square");
    3. if (lineCount > pageLength)
         pageCount++;
    4. if (page % 2 == 0)
         leftSide = true;
      else
         leftSide = false;
    1. if (x == y)
         println("Values are equal");
    2. if (answer > maxValue)
         println("Answer is wrong");
  1.  
    void setup()
    {
       int first = getInt("Please enter an integer:");
       int second = getInt("Please enter another integer:");
       println ("The two numbers that you entered were " 
                         + first + " and " + second);
       print(first + " is ");
       if (second % first != 0)
          print ("not ");
       println ("a multiple of " + second);
    } 
  2.  
    void setup()
    {
       double input = getDouble("Enter number");
       println("The number you entered: " + input);
       print("The absolute value of that number is: ");
       if (input >= 0)
          println(input);
       else
          println(-1 * input);
    } 
  3.  
    void setup()
    {
       int a = getInt("Please enter a value for a");
       int b = getInt("Please enter a value for b");
       print(a + "x + " + b + " = 0");
       if (a == 0 && b != 0)
          println(" is inconsistent. No solution exists.");
       else if (a == 0 && b == 0)
          println(" has infinitely many solutions.");
       else
          println(" has the solution: x = " + ((float) - b / a));
    }