Print Options

Card layout:

← Back to notecard set|Easy Notecards home page

Instructions for Side by Side Printing
  1. Print the notecards
  2. Fold each page in half along the solid vertical line
  3. Cut out the notecards by cutting along each horizontal dotted line
  4. Optional: Glue, tape or staple the ends of each notecard together
  1. Verify Front of pages is selected for Viewing and print the front of the notecards
  2. Select Back of pages for Viewing and print the back of the notecards
    NOTE: Since the back of the pages are printed in reverse order (last page is printed first), keep the pages in the same order as they were after Step 1. Also, be sure to feed the pages in the same direction as you did in Step 1.
  3. Cut out the notecards by cutting along each horizontal and vertical dotted line
Print these notecards...Print as a list

20 notecards = 5 pages (4 cards per page)

Viewing:

Java Problem Solving and Programming - CH 1 Exercises

front 1

How does a computer’s main memory differ from its auxiliary memory?

back 1

Main memory holds the current program and much of the data that the program is manipulating. The information stored in main memory typically is volatile, that is, it disappears when you shut down your computer.

Auxiliary memory, or secondary memory, exists even when the computer’s power is off.

front 2

After you use a text editor to write a program, will it be in main memory or auxiliary memory?

back 2

After you have closed the text editor it will be in auxiliary memory.

front 3

When a computer executes a program, will it be in main memory or auxiliary memory?

back 3

The program will be in main memory.

front 4

How does machine language differ from Java?

back 4

Machine language is the languange a computer can directly understand. Java is a programming language that is relatively easy for people understand and use. In order for a computer to run a Java program, it must first be translated into machine language.

front 5

How does bytecode differ from machine language?

back 5

When you compile a java class it is translated into bytecode. Bytecode is a machine language for a hypothetical computer know as a virtual machine. When you run a java program, the Java Virtual Machine (JVM) translates the bytecode into machine code.

front 6

What would the following statements, when used in a Java program, display on the screen?

int age;
age = 20;
System.out.println ("My age is");
System.out.println(age);

back 6

My age is
20

front 7

Write a statement or statements that can be used in a Java program to display the following on the screen:
3
2
1

back 7

System.out.println("3");
System.out.println("2");
System.out.println("1");

front 8

Write statements that can be used in a Java program to read your age, as entered at the keyboard, and display it on the screen.

back 8

java.util.Scanner keyboard = new java.util.Scanner(System.in);
System.out.println("Enter your age");
int age = input.nextInt();
System.out.println("Your age is " + age);

front 9

Given a person's year of birth, the Birthday Wizard can compute the year in which the person's nth birthday will occur or has occurred. Write statements that can be used in a Java program to perform this computation for the Birthday Wizard.

back 9

java.util.Scanner keyboard = new java.util.Scanner(System.in);
System.out.println("Enter the year you were born");
int yearBorn = keyboard.nextInt();
System.out.println("Enter birthday to check year for");
int birthday = keyboard.nextInt();
System.out.println("You will turn " + birthday + " in " + (yearBorn + birthday));

front 10

Write statements that can be used in a Java program to read two integers and display the number of integers that lie between them, including the integers themselves. For example, four integers are between 3 and 6: 3, 4, 5, and 6.

back 10

java.util.Scanner keyboard = new java.util.Scanner(System.in);
System.out.println("Enter the smaller integer");
int num1 = keyboard.nextInt();
System.out.println("Enter the larger integer");
int num2 = keyboard.nextInt();
for(int i = num1; i <= num2; i++)
{
System.out.println(i);
}

front 11

A single bit can represent two values: 0 and 1. Two bits can represent four values: 00, 01, 10, and 11. Three bits can represent eight values: 000, 001, 010, 011, 100, 101, 110, and 111. How many values can be represented by
(a)8 bits
(b)16 bits
(c)32 bits

back 11

(a)256
(b)65,536
(c)4,294,967,300

front 12

Find the documentation for the Java Class Library on the Oracle Web site. (At this writing, the link to this documentation is http://docs.oracle.com/javase/7/docs/api/.) Then find the description for the class Scanner. How many methods are described in the section entitled "Method Summary"?

back 12

55

front 13

Self-Test Question 27 asked you to think of some attributes for a song object. What attributes would you want for an object that represents a play list containing many songs?

back 13

Genre, Song Count, Total Time, List of Performers

front 14

What behaviors might a song have? What behaviors might a play list have? Contrast the difference in behavior between the two kinds of objects.

back 14

Song: Play, Pause, Stop
Playlist: Play All, Next Song, Previous Song, Remove Song

In the case of a song, behavior is for a single object (song). For a playlist, behavior is for a group of objects (songs).

front 15

What attributes and behaviors would an object representing a credit card account have?

back 15

Attributes: Card Type, Card Number, Card Holder's Name (First and Last), Card Holder's Address (Street, City, State and Zip), Expiration Date (Month and Year), Credit Limit, Balance

Behaviors: Make Payment, Refund Payment, Increase Credit Limit

front 16

Suppose that you have a number x that is greater than 1. Write an algorithm that computes the largest integer k such that 2^k is less than or equal to x.

back 16

x is greather than 1
k = 0
while 2^k is less than or equal to x
{
add 1 to k
}
subtract 1 from k

front 17

Write an algorithm that finds the maximum value in a list of values.

back 17

maxValue = -1
iterate through each list value
{
if list value is greater than maxValue then maxValue = list value
}

front 18

Write statements that can be used in a Java applet to draw the five interlocking rings that are the symbol of the Olympics. (Don't worry about the color.)

back 18

public void paint(Graphics g)
{
g.drawOval(40, 40, 120, 120);
g.drawOval(140, 40, 120, 120);
g.drawOval(240, 40, 120, 120);
g.drawOval(90, 130, 120, 120);
g.drawOval(190, 130, 120, 120);
}

front 19

Find the documentation for the class Graphics in the Java Class Library. (See Exercise 12.) Learn how to use the method drawRect. Then write statements that can be used in a Java applet to draw a square containing a circle. The circle's diameter and the square's side should be equal in size.

back 19

public void paint(Graphics g)
{
g.drawRect(10, 10, 100, 100);
g.drawOval(10, 10, 100, 100);
}

front 20

Write statements that can be used in a Java applet to draw the outline of a crescent moon.

back 20

public void paint(Graphics g)
{
g.drawArc(10, 10, 300, 300, 40 100);
g.drawArc(10, 20, 300, 240, 40, 100);
}