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.
Read Java Text Book pp. 667-670
Read Java Text Book pp. 644-652
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.
Read Java Text Book: pp. 25-40
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!
Beginning with LayoutExample3.java , implement a JButton to transfer the matrix data from the JTextArea (cArea) to the A matrix' JTextFields.
Make sure to use the current Matrix.java . This has a Matrix(String data, String delimeter) constructor that will be very useful.
1. Add an "AB" button to the south panel. Use the "A+B" button as an example.
2. Resize the Matrix C when necessary for AB. See LayoutExample2 above.
1. Add an "AB" button to the south panel. Use the "A+B" button as an example.
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().
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.
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.
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.]
Polygon.java (Fill in the blanks: BLANK_0, BLANK_1, BLANK_2)
Primes.java (Fill in the blanks: BLANK_0, BLANK_1, ..., BLANK_4.)
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)
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"); } }
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); } }
1. Use the IntelliJ IDE installed on your lab computer to create, build, and run the example Java program.
2. Decide on a method of storing your lab assigments, so that you can work on them during multiple class sessions. Then save the example program you just ran. e.g. Email your project to yourself, or copy it to your USB drive.
3. Shut down your lab computer. After it is shut down, wait for a few seconds.
4. Turn on your lab computer.
5. Retrieve your program from the email you sent or from your USB drive or other storage location, and then run it using the IntelliJ IDE installed on your lab computer.