BuiltWithNOF
April 1

Agenda:

    1. Syllabus
    2. Core Computers
    3. Java Applications
    4. Read Code examples
    5. Write Applications: Craps
    6. Methods
    7. Read Code with Methods
    8. Craps with Methods
    9. Practice

Assignment:

    1. Review for Test
    2. Craps program

 

 

 

 

 

 

 

 

Foundations of Computing Final:    Name ________________________

Read Code Question:

What is the output for the following code segment in main. Box your final answer

intA = 5; intB = 1; intC = 8;
while (intB < intC)
{
System.out.println ("yes" + intC);
intB = intB + 1;
if (intA > 3)
{
System.out.println ("more");
while (intA > intB)
{
System.out.println ("do it" + intB);
if (intB < 4)
{
intC = intC - 1;
System.out.println (intC);
if (intA == 5)
{
System.out.println ("done");
}
System.out.println ("finish");
}
intB++;
intA-=1;
}
System.out.println ("stop" + intB);
}
if (intC < 3)
{
System.out.println ("junk");
intC = intC - 1;
}
intC--;
}

 

Read Code with Methods Question:

What is the output for the following question? Put a box around your final answer.

public class New
{
static int a = 1;
static int b = 5;
public static void main( String args[] )
{
int a=3; int c=2; int d=4;
System.out.println(a+" "+b+" "+c+" "+d);
b =sec(a,b);
System.out.println(a+" "+b+" "+c+" "+d);
first(a);
System.out.println(a+" "+b+" "+c+" "+d);
}

static void first(int c)
{
int d = c+1;
System.out.println(a+" "+b+" "+c+" "+d);
b=7;
}

static int sec(int c, int a)
{
b = 9;
int d = a+1;
first(d);
System.out.println(a+" "+b+" "+c+" "+d);
return a;
}
}
 

Write a Java Method using simple arrays question:

Write a java method, assuming a filled array of integers, that is passed in a value and returns with the average score of all the odd numbers in the array that are between this passed value below the average and this passed value below the high score. For example, if you called Junk(5) and the average was 57 and the high score was 98, your program would return with the average of all the odd scores that were between 52 and 93. (5 less than the average and 5 less than the high)

 

 

 

 

 

Read a 2 dim array question:

What is the output for the following program?  Box your final answer.

import java.applet.Applet;
import java.awt.*;

public class New extends Applet
{

int board[][];
int row,col;

public void init()
{
board = new int[5][3];
board[0][1]=7;
board[3][0]= 3;
for (int x=1; x<5; x++)
for (int y=1; y<3; y++)
{
if (x == y) board[x][y] = x+y;
if (x<y) board[x][y] = y*x;
else board[x][y] = x-y+2;
}

}


public void paint(Graphics g)
{
for (int r=0; r<5; r++)
{
for (int c=0; c<3; c++)
{
g.drawString(String.valueOf(board[r][c]),c*20,r*20+20);
}
}
}
}
 

Arrays of Classes question:

Suppose you wanted to keep track of track stars. All track stars have a name and age. Sprinters have a 100 time and Throwers have the number of push-ups they can do.  You can only see and change the push-up number in the Throwers class.  Make the 3 classes you would need to store this information, including constructor and only the needed get and set methods.

 

 

 

 

 

 

Show how you would make an array of 100 Throwers

 

Make as the 5th Thrower  Jim who is 24 and can do 86 push-ups

 

Write a Java Method, assuming tcount throwers in a global array of Throwers that will pass in a value and return with the name of the oldest Thrower who can do more than the passed in number over the average number of push-ups..   So, Junk(6) would return with the name of the oldest thrower who can do more than 6 over the average push-ups of all the throwers.

 

Linked List question:

Look at the picture on the board. 

Write a System.out.println statement to print  Mary’s GPA

Write the needed statement to insert a new node  (Jim, 31, 2.78) between Mary and Ed in the list

 

Write a java method to print the average gpa of all folks over 30, assuming you have a much larger list.

 

 

Data Structure questions:

Write the classes needed to store the data on the board.

 

 

Write a class that can store the name and GPA of folks in a BST

 

Contrast a Stack with a Queue

 

 

Show a BST given the following inputs: 34, 67, 24, 15, 78, 35, 19, 36, 72

 

 

Show 2 trees you could have if you deleted 34 from the tree.

 

 

Explain a Hash search

 

Show a Heap if you entered values in this order: 35, 21, 84, 78, 95, 73, 11, 59, 82, 69.  Assume the largest if at the front.

 

Recursion questions:

What is the output for the following method, assuming you call Moves(4):

public void Moves(int s)
{

if (s>5) output.addItem("done"+s);
else
{
Moves(s+1);
output.addItem("mid "+s);
Moves(s+2);
output.addItem("exit"+s);
}
}
 

Write a recursive method to find a Doggo number. A doggo number is the sum of the previous 2 doggo numbers + 2.  The first 2 doggo numbers are 1 and 2..  So, the progression is   1, 2, 5, 9, 16, 27,...    Doggo(5) = 16, etc..

 

 

What is the Big O for the following algorithm? Assume s can get large,  t can get up to half of s, and z can get up to 10000

   for w = 100 to s/2
       a= 1000
       while (a<t)
             for w = 1 to z
                   c++
             a = a * 2;

 

[Home] [Syllabus] [Sessions]