Calculator program

public class Calculator extends ConsoleProgram
{
    public void run()
    {
        int first = readInt("First: ");
        int second = readInt("Second: ");
        int sum = first + second;
        System.out.println(sum);
    }
}
  1. How many variables are in this program?
  2. How many methods are in this program?
  3. How many classes are in this program?

Rewrite this program to work in "real" Java below:

 

 

 

 

 

 

What is tricky about the program below?
public class TrickyJava extends ConsoleProgram
{
    public void run()
    {
        int candyBars = 20;
        int friends = 5;
        System.out.println("Candy bars: " + candyBars);
        System.out.println("Friends: " + friends);
        int candyBarsPerPerson = candyBars / friends;
        // We expect it to be 4... and it is 4.
        System.out.println("Candy per person: " + candyBarsPerPerson);
        friends++;
        System.out.println("Candy bars: " + candyBars);
        System.out.println("Friends: " + friends);
        // We expect it to be 3.33.. and it is ..
        candyBarsPerPerson = candyBars / friends;
        System.out.println("Candy per person: " + candyBarsPerPerson);
    }
}
  1. How many variables are in this program?
  2. Why is the answer different than expected?
  3. What can be changed?

Paint Program #1:

Write a program to calculate the number of gallons of paint needed to paint a room if:

Comparison program:

Given 2 int values, print the smallest number if both numbers are >0, or print the largest number if they are both < 0. Otherwise print "out of range"