← Radourmeire Home

Intro to CS with Java

Grading

Java Text Book: Introduction to Programming with Java

Java Tutorial: https://docs.oracle.com/javase/tutorial/tutorialLearningPaths.html


matcalc

Lecture Notes

For the midterm and final exams, you only need to know what was taught in the lectures, which is summarized in the notes. The references address the central topics of the lecture, but include additional material.

Week 14

Week 14 lecture notes

Primitive vs. Reference Type Variables in Java :

Diagrams

Source Files

References:

What is an Object?
What is a Class?

Week 12

Week 12 lecture notes

References:

Arrays

Week 10

Week 10 lecture notes

Week 7

Week 7 lecture notes

References:

Variables
Primitive Data Types

Weeks 3 & 4

Week 3 lecture notes
Week 4 lecture notes

References:

Binary Tutorial
Computer Number Systems
Boolean Algebra

Assignments:

Week 2.8

Read Java Text Book pp. 667-670.

Week 2.1

Read Java Text Book pp. 644-652.

Week 14

Read the Matrices Tutorial so that, for a scalar s and two matrices A and B of appropriate dimensions, you can compute A + B, sA, A - B, AT, AB, |A|, and A-1. For ways of calculating A-1, see 2x2 Inverse. There are links at the bottom of that page to pages that explain how to find the inverse of a matrix that is larger than 2x2. For ways of calculating |A|, see Determinant.

Week 10

Read Java Text Book: pp. 25-40.

Week 2

Read Java Text Book: pp. 1-22.


NOTE: Java Text Book page 1 is page 35 of the PDF. In the assignments and labs, the page numbers are the actual book page numbers (not the PDF page numbers). To calculate the PDF page number, just add 34 to the actual book page number!


Labs:

Week 2.11

1. Implement a JButton to transfer the matrix data from the JTextArea (cArea) to the A matrix' JTextFields.

2. Begin completing the remaining methods.

MatrixCalculator.java

Matrix.java [This has a Matrix(String data, String delimeter) constructor that will be very useful.]

Fraction.java

Week 2.9

1. Add an "sA" button to the south panel.

2. Add an "AT" button to the south panel. Ensure C has the correct dimensions.

3. Correct the jittering effect observed when adjusting a horizontal slider.

LayoutExample2.java

Matrix.java

Week 2.7

1. Add an "AB" button to the south panel. Use the "A+B" button as an example.

LayoutExample.java

Matrix.java

Week 2.5

I. Modify the SimpleWindow program to open an input dialog box prompting the user to enter their name. Use System.out.println() to write the user input String [obtained from JOptionPane.showInputDialog()] to the console.

II. Update the label text using the user input String. To do this, make the declaration of the JLabel a static field of the SimpleWindow class. Then you can call setText() on the label from inside main().

SimpleWindow.java

SimpleWindow2.java

SimpleWindow3.java

Week 2.3

Implement a simple AWT/Swing application that presents a window (JFrame) with an input text box (JTextField), an output text box, and a "Factorial" button (JButton). The user should be able to type a small integer into the input text box, and then click the button to see the factorial of the input integer displayed in the output text box. You can begin with the code on pages 665-666 in section 16.12.

Week 2.1

Implement a simple AWT/Swing application that displays a message in a JLabel component. The JLabel should be added to a JFrame. You can begin with the code on pg. 648 of Java Text Book. Try making some changes, and begin considering how to implement your project using AWT/Swing.

SimpleWindow.java

SimpleWindow2.java

SimpleWindow3.java


Week 16

MatrixTest.java

Matrix.java [Complete the Matrix.multiply(int a) method: Given a Matrix A and an int a, A.multiply(a) should return a new Matrix that is the same as Matrix A but with each element multiplied by a. Add a test of the multiply method in MatrixTest.java, similar to the test of the add method. Then finish the remaining operations: A - B, AT, AB, |A|, and A-1. For ways of calculating A-1, see 2x2 Inverse. There are links at the bottom of that page to pages that explain how to find the inverse of a matrix that is larger than 2x2. For ways of calculating |A|, see Determinant.]

Week 15

PolygonTestG.java

Polygon.java (Fill in the blanks: BLANK_0, BLANK_1, BLANK_2.)

Point.java

Week 13

Primes.java (Fill in the blanks: BLANK_0, BLANK_1, ..., BLANK_4.)

soe

Sieve animated GIF image: SKopp, CC BY-SA 3.0, via Wikimedia Commons


Week 11

   Write a program that chooses a number between 1 and 1,000,000 and then asks you to guess the number. 
If your guess is correct, the program should print "you win" as well as the number of guesses you took 
to find the number, and then terminate. If your guess is incorrect, the program should print "higher" 
or "lower" accordingly and then ask you for another guess. See fig. 8 in the Week 10 lecture notes for Scanner code and loop 
structures that you might find helpful. 
                
Math.random() returns a double in the range [0,1).  To choose an integer between 1 and 1000000, you can use 
                 
int secret = (int)(Math.random() * 1000000) + 1;
                 
For extra credit : determine an upper bound on the number of guesses needed to find the number.
Compare the number of guesses the user took to find the number with this upper bound to determine a
score.
                
Math.log(x) returns the base-10 log of x.  You can compute the base-2 log of a number x using the fact that 
                
log_2(x) = log_10(x)/log_10(2)

Week 8

public class Calculations {
    public static void main(String[] args) {
        float PI = 3.1415f;
                		
        float r = 1;
        float a, c;
                		
        a = ; // BLANK_0 : PIr^2
        c = ; // BLANK_1 : 2PIr
                		
        System.out.println("a = " + a);
        System.out.println("c = " + c);
                		
        // Convert the temperature from Celcius (C)
        // to Fahrenheit (F).
                		
        float t_c = 22;
        float t_f = ; // BLANK_2 : (9/5)t_c + 32
                		
        System.out.println(t_c + "C" + " = " + t_f + "F");
                		
    }
}

Week 4

public class XOR {
    public static void main(String[] args) {
        int a = 5;
        int b = 7;
                        
        System.out.println(a + " " + b);
                
        a = a ^ b; // Step 1
                   // Step 2
                   // Step 3
                                   
        // Complete the final two steps of this algorithm using only the XOR (^) and the assignment (=) operators, without using a temporary variable.  
        // The next two steps are similar to the final two steps of the previous variation of this algorithm, which uses + and -.  (See the Week 4 lecture notes.) 
        // HINT: How can XOR be used to get the same result as the subtraction step in the previous variation of this algorithm?  
        //       What is the value of (a ^ b) ^ b ?
                
        System.out.println(a + " " + b);
   }
}