CSE 142
- index.shtml"> images/home_icon.png" class="sidebaricon" alt="main" /> Main Page
- syllabus.pdf"> images/syllabus_icon.png" class="sidebaricon" alt="syllabus" /> Syllabus
Coursework
- calendar.shtml">images/lectures_icon.png" class="sidebaricon" alt="lectures" /> Calendar handouts.shtml">images/diff_icon.png" alt="handouts" width="16" height="16" class="sidebaricon" /> Handouts -->
- homework.shtml">images/homework_icon.png" class="sidebaricon" alt="homework" /> Homework
- sections.shtml">images/lab_info_icon.png" class="sidebaricon" alt="sections" /> Sections
- labs.shtml">images/labs_icon.png" class="sidebaricon" alt="labs" /> Labs
- textbook.shtml">images/textbook_icon.png" class="sidebaricon" alt="textbook" /> Textbook
- working_at_home.shtml">images/working_at_home_icon.png" class="sidebaricon" alt="working at home" /> Java Software
- exams.shtml">images/exams_icon.png" class="sidebaricon" alt="exams" /> Exams python.shtml">images/python_icon.gif" class="sidebaricon" alt="python" /> Python --> jgrasp.shtml">images/jgrasp_icon.gif" class="sidebaricon" alt="jGRASP Tutorial" /> jGRASP Tutorial -->
Getting Help
- staff.shtml">images/staff_icon.png" class="sidebaricon" alt="staff" /> Course Staff
- "> images/lab_schedule_icon.png" class="sidebaricon" alt="lab schedule" /> TA IPL Schedule
- message_board.shtml">images/message_board_icon.png" class="sidebaricon" alt="message board" /> Message Board
- images/practiceit.png" class="sidebaricon" alt="icon" /> Practice-It! practicum.shtml">images/labs_icon.png" class="sidebaricon" alt="icon" /> Practicum -->
Check Scores
- ">images/myuw_icon.png" class="sidebaricon" alt="myuw" /> Canvas
- gradeit.shtml">images/gradeit_icon.png" class="sidebaricon" alt="grade-it" /> Grade Sheets
- regrade.shtml">images/survey_icon.gif" alt="regrade" width="32" height="32" class="sidebaricon" /> Regrade Policy
- /grades/gradenator.html"> Grade Calculator
Other
-
images/cool_links_icon.png" class="sidebaricon" alt="cs cool stuff" /> CS Cool Stuff-->
explore.shtml">images/python_icon.gif" alt="explore" class="sidebaricon" /> Exploration Sessions -->
- honors.shtml">images/atom.png" alt="honors" width="24" height="24" class="sidebaricon" /> Honors Seminar
- links.shtml">images/links_icon.png" class="sidebaricon" alt="links" /> Links faq.shtml">images/faq_icon.png" class="sidebaricon" alt="FAQ" /> FAQ -->
Sections
This page lists the section topics for each week, as well as the section homework that is due at the beginning of section each week.
Written Assignments
Each week we will assign a written homework assignment to be turned in and discussed in section. These are meant as "warm up" problems to get you thinking about the topics we cover that week. It will be graded for effort, not for whether or not you have the right answers. You will receive 1 point for each written assignment you bring to section, and 2 points for attendance. The maximum number of section attendance/hw points that you can receive is 20. As a guideline, we expect you to spend around 30 to 60 minutes on section homework each week. If you find yourself spending much more than that, you can stop working for that week and let your TA know that you ran out of time. If this becomes a common occurrence, talk to your TA about what you might be struggling with.
You will not be graded on whether you have a perfect solution, but on whether you have demonstrated a reasonable effort. Therefore, you should show work that demonstrates how you got your answer rather than just writing the answer by itself.
Section 9: Final practice
Thursday, June 6
Exercises: Solve the following problem on paper and bring your sheet of paper to your section on Thursday:
-
Inheritance.
Assume that the following classes have been defined:
public class George extends Sally { public void method2() { System.out.println("george 2"); } } public class Fred { public void method1() { System.out.println("fred 1"); } public void method2() { System.out.println("fred 2"); } public String toString() { return "fred"; } } public class Harold extends Sally { public String toString() { return "harold"; } } public class Sally extends Fred { public void method1() { System.out.println("sally 1"); } public String toString() { return "sally"; } }
Consider the following code fragment:Fred[] elements = {new Sally(), new Fred(), new George(), new Harold()}; for (int i = 0; i < elements.length; i++) { System.out.println(elements[i]); elements[i].method1(); elements[i].method2(); System.out.println(); }
What output is produced by this code? (write the output as a series of 3-line columns in order from left to right)
Section 8: Objects
Thursday, May 30
Exercises: Solve the following problems on paper and bring your sheet of paper to your section on Thursday:
-
Self-Check 8.4 (reference mystery, p578).
The following program produces 4 lines of output. Write each line of
output below as it would appear on the console.
public class ReferenceMystery3 { public static void main(String[] args) { int a = 7; int b = 9; Point p1 = new Point(2, 2); Point p2 = new Point(2, 2); addToXTwice(a, p1); System.out.println(a + " " + b + " " + p1.x + " " + p2.x); addToXTwice(b, p2); System.out.println(a + " " + b + " " + p1.x + " " + p2.x); } public static void addToXTwice(int a, Point p1) { a = a + a; p1.x = a; System.out.println(a + " " + p1.x); } }
You can use PracticeIt to solve this problem. If you do, be sure to write your answer on a sheet of paper. -
Self-Check 8.18 (Object Constructors, p580).
The constructor in the following class definition has two major
problems. What are they? Describe the issues, and write a working version
of the constructor:
public class Point { int x; int y; // The constructor: public void Point(int initialX, int initialY) { int x = initialX; int y = initialY; } }
You can use PracticeIt to solve this problem. If you do, be sure to write your answer on a sheet of paper.
Section 7: Arrays
Thursday, May 23
Exercises: Solve the following problems on paper and bring your sheet of paper to your section on Thursday:
-
Consider the following method:
public static void arrayMystery(int[] array) { for (int i = 0; i < array.length - 1; i++) { if (array[i] < array[i + 1]) { array[i] = array[i + 1]; } } }
Indicate what values would be stored in the array after the method
a. input =arrayMystery
executes if each integer array below is passed as a parameter to it.{2, 4}
b. input ={1, 3, 6}
c. input ={7, 2, 8, 4}
d. input ={5, 2, 7, 2, 4}
e. input ={2, 4, 6, 3, 7, 9}
-
Chapter 7, Self-Check Problem #10:
max
(p517). Write a method namedmax
as described. Find the prompt and check your answer on Practice-It.
Section 6: File input/output
Thursday, May 16
Exercises: Solve the following problems on paper and bring your sheet of paper to your section on Thursday:
For the next several questions, consider a file
called readme.txt
that has the following contents:
6.7 This file has several input lines. 10 20 30 40 test
-
Self-Check 6.12 (file processing, p433).
What would be the output from the following code when it is run on
the
readme.txt
file?Scanner input = new Scanner(new File("readme.txt")); int count = 0; while (input.hasNextLine()) { System.out.println("input: " + input.nextLine()); count++; } System.out.println(count + " total");
-
Self-Check 6.13 (file processing, p433).
What would be the output from the code in the previous exercise if the
calls to
hasNextLine
andnextLine
were replaced by calls tohasNext
andnext
, respectively? -
Self-Check 6.14 (file processing, p434).
What would be the output from the code in the previous exercise if the
calls to
hasNextLine
andnextLine
were replaced by calls tohasNextInt
andnextInt
, respectively? How abouthasNextDouble
andnextDouble
?
Section 5-5: Midterm practice
Thursday, May 9
Exercises: Solve the following problem on paper and bring your sheet of paper to your section on Thursday:
-
Assertions. You will identify various assertions as
being either always true, never true or sometimes true/sometimes false at
various points in program execution. The comments in the method below
indicate the points of interest.
public static int mystery(int x) { int y = 1; int z = 0; // Point A while (x > y) { // Point B z = z + x - y; x = x / 2; // Point C y = y * 2; // Point D } // Point E return z; }
Copy the table below onto a sheet of paper and fill it in with the words ALWAYS, NEVER or SOMETIMES.x > y
z > 0
y % 2 == 0
Point A Point B Point C Point D Point E
Section 5: while
, Random
, boolean
Thursday, May 2
Exercises: Solve the following problems on paper and bring your sheet of paper to your section on Thursday:
-
while
loop mystery For each method call, make a table showing the values thatx
andy
have as you execute thewhile
loop for that particular call. For example, for the first call, the table looks like this:mystery(7, 5); x y -------- 7 5 2 4 -2 3
You are to write out the tables for the other two calls. This problem is included in PracticeIt, but PracticeIt doesn't ask for the tables (just the final output). But you can still use PracticeIt to see this problem. -
Programming Exercise 5.4
(
randomX
, p382). You can use PracticeIt to solve this problem. If you do, either print what you end up with so that you can turn it in or copy the code to your paper.
Section 4: if/else
, Scanner
, return
Thursday, April 25
Exercises: Solve the following problems on paper and bring your sheet of paper to your section on Thursday.
-
Programming Exercise 4.1 (
fractionSum
, p309). Remember that you can use PracticeIt to solve this problem. If you do, either print what you end up with so that you can turn it in or copy the code to your paper. -
Programming Exercise 4.12 (
printTriangleType
, p311). Remember that you can use PracticeIt to solve solve this problem. If you do, either print what you end up with so that you can turn it in or copy the code to your paper.
Section 3: parameters, graphics
Thursday, April 18
Exercises: Solve the following problems on paper and bring your sheet of paper to your section on Thursday.
-
Parameter Mystery.
Consider the following program:
public class Params { public static void main(String[] args) { int x = 15; int y = 2; int z = 9; mystery(x, y, z); mystery(z, x, y); mystery(y, z, x); } public static void mystery(int a, int b, int c) { System.out.println("The " + a + " monkeys ate " + (b + c) + " bananas"); } }
Make a table that shows what value is being passed to each of a, b, and c for each of the three calls and then indicate the output produced by the program. -
Programming Exercise 3G.1 (
MickeyBox
, p227). Remember that you can use PracticeIt to solve this problem. If you do, either print what you end up with so that you can turn it in or copy the code to your paper.
Section 2: Expressions, for
loops
Thursday, April 11
Exercises: Solve the following problems on paper and bring your sheet of paper to your section on Thursday.
-
From Self-Check 2.3 (expressions, p119).
Solve the following expressions (see note below):
14 / 7 * 2 + 30 / 5 + 1 (12 + 3) / 4 * 2 813 % 100 / 3 + 2.4
-
From Self-Check 2.4 (expressions, p120).
Solve the following expressions (see note below):
4.0 / 2 * 9 / 2 2.5 * 2 + 8 / 5.0 + 10 / 3
-
Self-Check 2.31 (for loops, p126).
What is the output of the following sequence of loops?
for (int i = 1; i <= 2; i++) { for (int j = 1; j <= 3; j++) { for (int k = 1; k <= 4; k++) { System.out.print("*"); } System.out.print("!"); } System.out.println(); }
For the expression problems, please show some work rather than just writing the answer. Write out sub-expressions as you compute their values, and circle or underline operands to show precedence, as is done in the section on "Precedence" in chapter 2 of the textbook (pages 70-73). For example:
2 + 19 % 5 - 11 * (5 / 2)
2 + 19 % 5 - 11 * 2
2 + 4 - 11 * 2
2 + 4 - 22
6 - 22
-16
Section 1: Basic Java, static methods
Thursday, April 4
Complete the introductory survey if you haven't done so already.