CS 151 - Computer Science I (Section 01)
Spring-2017
Classes: TR 9:25am - 10:40am, Maria Sanford Hall 310
Instructor: Dr. Zdravko Markov, 30307 Maria Sanford Hall, (860)-832-2711,
http://www.cs.ccsu.edu/~markov/,
e-mail: markovz at ccsu dot edu
Office hours: MW 10:45am - 12:15pm, TR 2:00pm - 3:30pm, or by appointment.
Catalog description: First course in Computer Science. Introduces
the fundamental concepts of computer programming with an object-oriented
language with an emphasis on analysis and design. Topics include data types,
selection and iteration, instance variables and methods, arrays, files,
and the mechanics of running, testing and debugging.
Prerequisites: MATH 152 (may be taken concurrently)
Course Learning Outcomes:
-
Learn the basic principles of object-oriented programming and the resources
available to help them write JAVA programs (editors, JAVA libraries, on-line
help manuals, and JAVA development environments).
-
Learn the basic programming constructs, namely primitive data, variables,
assignment statement, arithmetic operators, parameter passing.
-
Learn the main control structures, namely Boolean expressions, conditional
statements, loops.
-
Understand and implement Java classes and use them in definite application
settings. Understand the ideas of abstraction and encapsulation, and incorporate
them into program design.
-
Understand and utilize text files and basic input/output operations.
-
Learn arrays of primitive data and arrays of objects.
-
Learn how to interpret non-trivial application problems (problem analysis)
and translate them into pseudo-code (program design) before implementing
them in JAVA.
Program Educational Objectives: CS 151 is part of the core CS program
and is designed in accordance with the Program Educational Objectives and
the Student Outcomes as specified in the Department
Mission Statement. The course Learning Outcomes support the following
Student Outcomes, wnich are part of the corresponding Program Educational
Objectives:
-
Graduates will gain a broad understanding of the fundamental theories,
concepts, and applications of computer science.
-
Outcome (a): An ability to apply knowledge of computing and mathematics
appropriate to the discipline.
-
Outcome (b): An ability to analyze a problem, and identify and define the
computing requirements appropriate to its solution.
-
Outcome (c): An ability to design, implement, and evaluate a computer-based
system, process, component, or program to meet desired needs.
-
Graduates will be prepared to apply their understanding in a wide range
of careers in computer science and information technology.
-
Outcome (i): An ability to use current techniques, skills, and tools necessary
for computing practice.
Required textbook: Lewis & Loftus, Java Software Solutions:
Foundations of Program Design, 8-th Edition, Addison-Wesley, 2015 (the
7-th edition may also be used).
Required software: BlueJ - an integrated Java programming environment
(http://www.bluej.org/)
Class Participation: All students are expected to attend class
sessions regularly. If you must miss a test, try to inform the instructor
of this in advance. In case of missed classes and work due to plausible
reasons (such as illness or accidents) limitted assistance will be offered.
Unexcused absences will result in the student being totally responsible
for the make-up process.
Assignments and tests: Reading and problem assignments are listed
under the schedule of classes. Some of the problems will be worked in class.
There will be quizzes, two tests and a final exam.
They will include material from the textbook, the lectures, and the programming
projects.
Programming projects: There will be 6 programming projects
requiring the use of BlueJ to write and run Java programs. The projects
with their due dates are listed below in the schedule of classes (the project
descriptions are given on separate pages). All projects must be submitted
through the class page in Blackboard Learn course management system
available at https://ccsu.blackboard.com/.
Honesty policy: The CCSU honor code for Academic Integrity is
in effect in this class. It is expected that all students will conduct
themselves in an honest manner and NEVER claim work which is not their
own. Violating this policy will result in a substantial grade penalty,
and may lead to expulsion from the University. You may find it online at
http://web.ccsu.edu/academicintegrity/.
Please read it carefully.
Grading: The final grade will be based on projects (50%),
quizzes
(10%), tests (20%), and the final exam (20%), and will
be affected by classroom participation, conduct and attendance. All grades
will be availabe from
Blackboard Learn. The letter grades will be
calculated according to the following table:
A |
A- |
B+ |
B |
B- |
C+ |
C |
C- |
D+ |
D |
D- |
F |
95-100 |
90-94 |
87-89 |
84-86 |
80-83 |
77-79 |
74-76 |
70-73 |
67-69 |
64-66 |
60-63 |
0-59 |
Unexcused late submission policy: Projects submitted more
than two days after the due date will be graded one letter grade
down. Projects submitted more than a week late will receive
two letter grades down. No submissions will be accepted more
than two weeks after the due date.
Students with disabilities: Students who believe they need course
accommodations based on the impact of a disability, medical condition,
or emergency should contact me privately to discuss their specific needs.
I will need a copy of the accommodation letter from Student Disability
Services in order to arrange class accommodations. Contact Student Disability
Services, Willard Hall, 101-04 if you are not already registered with them.
Student Disability Services maintains the confidential documentation of
your disability and assists you in coordinating reasonable accommodations
with your faculty.
Tentative schedule of classes, assignments, projects and tests
Note: Dates for classes, assignments, and tests will be posted at due time and may change
(see also University
Calendar). Additional material may be posted. Check the schedule regularly
for updates!
-
Jan 17, 19: Introduction to computers and programming
-
Topics:
-
What
is Computer Science?
-
Computational Thinking: http://www.cs.cmu.edu/~CompThink/,
http://www.cs4fn.org/computationalthinking/
-
A little history: Who
Invented the Computer?
Turing Machines,
A Turing Machine Applet,
Alan
Turing Year, John
von Neumann, IT
History Society, The
Virtual Museum of Computing,
-
Von
Neumann Architecture, non-Von Neumann computing (NN,
ALVINN)
-
Computer Programming
-
Representing information in computers, number systems ("there are 10 types
of people in this world, those who understand binary and those who don't")
-
Lecture slides: LEWIS_01.ppt
-
Programs/Exercises: Hello.asm
(runs with PCSpim),
Hello.java
(runs with BlueJ)
-
Assignments:
-
Jan 24, 26: Java language and Object-Oriented Programming
-
Topics:
-
Writing and running Java programs
-
Comments, identifiers and reserved words
-
Program development cycle
-
Object-Oriented programming
-
Print method, character strings, escape sequences
-
Lecture slides: LEWIS_01.ppt
-
Programs/Exercises:
-
Hello.java
-
Print "This is my first Java program" on the next line by adding another
print statement,
-
or (2) by including the message in the same print statement (escape sequence).
-
PlusOperator.java
-
Remove the parentheses enclosing the arithmetic addition and explain what
happens and why.
-
Try other parenthesizings and explain the results.
-
Print strings and arithmetic expressions with separate statements.
-
Write a program to compute the celsius equivalent of today's temperature
(use the formula C=(F-32)*5/9). Use BlueJ to create a new project and a
new class, then add the code for the main method.
-
Assignments:
-
Read Sections 1.4 - 1.6, 2.1
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 1.21-1.26, 1.28-1.32, 2.1-2.8
-
Do Exercises: 1.2, 1.3, 1.14 (7-th ed. 1.15), 1.15 (7-th ed. 1.16), 1.17
(7-th ed. 1.18), 1.18, 1.20, 2.3-2.6 (7-th ed. 2.2-2.5)
-
Do Programming Projects: 1.1, 1.2, 1.3
-
Jan 31: Submit Programming
Project 0
-
Jan 31 - Feb 1: Take Quiz 1 (Sections 1.1-1.6, 2.1) online in
Blackboard
-
Jan 31, Feb 2, 7: Data and Expressions
-
Topics:
-
Character strings
-
Primitive data types. Variables. The assignment statement and arithmetic
operators.
-
Data conversion
-
Interactive programs. The Scanner class.
-
Lecture slides: LEWIS_02.ppt
-
Programs/Exercises:
-
Arithmetic.java
(note the difference between integer division and floating point division,
explain the modulo operation)
-
PrimitiveTypes.java
-
Explain the output
-
Print the values of the variables (combine them in the string)
-
Fix the overflow problem (two's complement representation) with long, float,
and double types and explain the difference
-
Try 2.147483647E9 instead of 2147483647 and explain what happens and why
(narrowing conversion)
-
GasMileage.java
(Listing 2.9)
-
What happens if you enter 20.5 for miles? Fix the problem in two ways.
-
What happens if enter miles and gallons on the same line?
-
Modify the program so that it reads two lines of inputs with car, miles,
and gallons (separated by blanks) and prints mpg for each car.
-
Fraction.java
(see also Rational
number,
Mixed
numbers)
-
Explain results for a=1, b=100000001, c=1, d=100000002 (underflow)
-
Print the sum of the fractions as a rational number
-
Print the sum of the fractions as a mixed number number
- Write a program, which asks the user for a change amount in cents and computes and prints the number of quarters, dimes, nickels, and pennies to be returned.
-
Assignments:
-
Read Chapter 2
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 2.9-2.29, 2.31-2.37
-
Do Exercises: 2.7-2.12 (7-th ed. 2.6-2.11)
-
Do Programming Projects: 2.2-2.6
-
Feb 7 - 8: Take Quiz 2 (Chapter 2) online in Blackboard
-
Feb 14: Submit Programming
Project 1
-
Feb 14, 16: Using classes and objects
-
Topics
-
Creating objects, aliases, wrapper classes
-
The Strings class
-
The Random class, packages
-
The Math class
-
Enumerated types
-
Lecture slides: LEWIS_03.ppt
-
Programs/Exercises:
-
StringMutation.java,
RandomNumbers.java,
Quadratic.java
-
Apply mutation4 to the original string (phrase). Explain and fix the error.
-
Write a program that reads a string and prints a random substring.
-
Write a program that generates a random quadratic equation and prints its
roots.
-
StringObjects.java
-
Write a program to read two strings and print true/false if they are equal/not
equal.
-
Extend the program with the compareTo method.
-
Translate.java
(Read a double digit number (20-99) and print it in words, e.g. 35 should
print as "thirty-five")
-
Objects.java
(make the changes and explain the results)
-
IceCream.java
(Assign chocolate flavor to cone3 and compare it with cone2 using "=="
and "equals")
-
Digits.java
(What happens with a wrong input? Extend the program to read input like
"two plus three" and print the result).
-
Assignments:
-
Read Sections 3.1 - 3.8
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 3.1 - 3.9, 3.16 - 3.21, 3.29 - 3.31, 3.32
- 3.35
-
Do Exercises: 3.4, 3.5, 3.7 - 3.10 (7th ed. 3.3, 3.4, 3.6 - 3.9)
-
Do Programming Projects: 3.1 - 3.3
-
Feb 21-22: Take Quiz 3 (Chapter 3) online in Blackboard
-
Feb 21, 23, 28: Decision making and Loops
-
Topics
-
Boolean expressions and logical operators
-
Comparing data and objects
-
Conditionals: the if - else and switch statements
-
Loops: the while statement
-
Lecture slides: LEWIS_05.ppt
-
Programs/Exercises:
-
CheckInput.java,
Type.java
(change the intervals to open/close, use if-else to read and validate a
percentage value)
-
Write a program to read and validate a tip percentage and apply it to a
given restaurant bill.
-
Age.java
(add age intervals - kid (<=18), adult (18,65), senior (>=65), add a
birthday message)
-
See Top
25 Most Dangerous Programming Errors. Add input type and range validation
to Age.java
-
Calculator.java
(replace the if-else-if structure with a switch, note the type of the expression
in the switch statement)
-
Gcd.java
(implement the version based on subtraction)
-
Grade.java
(add input type verification)
-
Write a program to add two rational numbers (see Fraction.java) and simplify
the sum using GCD.
-
StudentGrades.java
(use a sentinel value or a question to the user for the stopping condition,
do counting and averaging in grade intervals - excellent (> 89), ok [60,89],
and failure (< 60))
-
Assignments:
-
Read Sections 5.1 - 5.4, 6.1
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 5.1 - 5.23, 6.1 - 6.4
-
Do Exercises: 5.2 - 5.5, 5.7 - 5.11
-
Do Programming Projects: 5.1 , 5.3, 5.4
-
March 7: Submit Programming
Project 2
-
March 2, 7, 21: Loops continued
-
Topics
-
The do and for statements
-
Leading decision (pretest) vs. trailing decision (posttest) loops
-
Nested loops
-
Lecture slides: LEWIS_06.ppt
-
Programs/Exercises:
-
PrintDigits.java
-
What happens with input 0? Change the while-loop to a do-loop.
-
Compute the sum of the digits of an integer.
-
Use nested loops to prove experimentally that if the sum of the digits
of a number is 9, then the number is multiple of 9
-
Loops.java
-
Move the index increment in the beginning of the while and do loops, explain
the difference
-
Print the squares from 0 to 100 with increments of 5
-
Use user specified range and increment
-
Print the multiplication table for 9 (or for a user specified number)
-
Guess.java
-
Change the range of numbers. What is the optimal strategy?
-
Include a counter to count the number of guesses
-
Change the do-loop with a while-loop
-
Series.java
-
Change the while-loop to do-loop or for-loop.
-
Use an outer loop (nested loops) for n=1,2,4,8,...,2^m to print a table
of n and sum
-
Use a conditional print (i % 100 == 0) instead of nested loops to print
the table (compare efficiency).
-
Use powers of 2 in the conditional print (Math.log(i)/Math.log(2) % 2 ==
0).
-
Find the first n for which sum >= 10.
-
Modify the series to 1/2+1/4+1/8+1/16 +... and do the convergence experiments.
See Zeno's
paradox and an interactive
demo.
-
str2int.java
(change the for-loop to while-loop, print the position of the wrong input
character)
-
Pi.java
-
Iteration.java
-
Factors.java
-
Print the sum of the proper factors of each number
-
For each number print if it is deficient, abundant or perfect (see these
links deficient,
abundant
or perfect).
-
Count how many numbers are deficient, abundant and perfect.
-
Primes.java
(change the for-loop to a while-loop), for more information about prime
numbers see this link.
-
Assignments:
-
Read Sections 6.3, 6.4
-
Run the programs and do the exercises described above
-
Answer the Self-Review Questions after Sections 6.1, 6.3, 6.4
-
Do Exercises 6.1 - 6.11
-
Do Programming Projects 6.1 - 6.3.
-
March 28: Submit Programming
Project 3
-
March 9: Test 1 (Chapters 2, 3, 5, 6)
-
March 23, 28: Writing classes
-
Topics
-
Writing user-defined classes and methods
-
Encapsulation and visibility modifiers
-
Parameters
-
Constructors, accessors, mutators
-
Instance and local data
-
Lecture slides: LEWIS_04.ppt
-
Programs/Exercises:
-
Die.java,
RollingDice.java
(pass the initial face value as a parameter of the constructor, change
visibility modifiers to access instance variables directly, roll dice in
a loop until their face values are equal, compute probability)
-
Account.java,
Transactions.java
(write a loop to find out after how many years the balance will double,
write a method to set the interest rate)
-
Assignments:
-
Read Sections 4.1 - 4.5
-
Answer the Self-Review Questions 4.1 - 4.25
-
Do exercises 4.5 - 4.8
-
Do Programming Projects 4.1 - 4.4, 4,6, 4.9
-
Run the programs and do the exercises described above
-
March 30, April 4: Java classes continued
-
Topics
-
Parameter passing
-
Static variables and static methods
-
Dependencies among classes, and dependencies among objects of the same
class
-
Lecture slides: LEWIS_07.ppt
-
Programs/Exercises:
-
Rational.java,
AddRationals.java
(do the suggested exercises)
-
Series1.java
(do the suggested exercises)
-
Slogan.java,
SloganCounter.java
-
Static variables/methods: change Slogan.getCount() to obj.getCount(), remove/add
static to count and getCount()
-
Visibility modifiers: change/remove the visibility modifier of getCount())
and count,
-
Encapsulation: replace Slogan.getCount() with Slogan.count
-
Instance/local variables: add method setCount(int x), add/remove int in
int count=x
-
Assignments:
-
Read Sections 7.1 - 7.4
-
Answer the Self-Review Questions 7.6 - 7.13
-
Do exercises 7.1, 7.4, 7.11
-
Do Programming Projects 7.1, 7.2
-
Run the programs and do the exercises described above
-
April 4-5: Take Quiz 4 (Chapters 4 and 7) online in Blackboard
-
April 11: Submit Programming
Project 4
-
April 6: Still more Java classes
-
Topics
-
The this reference
-
Method parameters
-
Method overloading
-
Lecture slides: LEWIS_07.ppt
-
Programs/Exercises:
-
Scope.java,
Num.java
(modify setValue(int value) and use the "this" reference, add static to
instance variable value)
-
Num.java,
ParameterModifier.java,
ParameterTester.java
-
try to add static to setValue() in class Num
-
add static to value in class Num and explain the output
-
add Num next; and another constructor Num(value, next) to class
Num
-
create a chain (list) of numbers: Num a = new Num(0); a = new Num(1,a);
a = new Num(2,a);
-
write a loop to print all numbers along the chain
-
use a loop to create a list of numbers: Num x=null; for (int i=1;i<=10;i++)
x = new Num(i,x);
-
Assignments:
-
Read Sections 7.7, 7.8
-
Run the programs and do the exercises described above
-
Do exercises 7.2, 7.3, 7.5
-
April 11: Test #2 (Chapters 4 and 7)
-
April 13: Working with text files
-
Topics
-
Lecture slides: LEWIS_05.ppt
-
Programs/Exercises:
-
Assignments:
-
Read Sections 5.5
-
Answer the Self-Review Questions 5.24, 5.25
-
Do Programming Projects 5.13, 5.14
-
Run the programs and do the exercises described above
-
April 20: Submit Programming
Project 5
-
April 18, 20, 25: Arrays
-
Topics.
-
Array elements
-
Declaring and using arrays of primitive data types
-
Passing arrays as parameters
-
Lecture slides: LEWIS_08.ppt
-
Programs/Exercises:
-
Assignments:
-
Read Sections 8.1, 8.2
-
Answer the Self-Review Questions 8.1 - 8.13
-
Do Exercises 8.1, 8.4, 8.6 - 8.10
-
Do Programming Projects 8.1, 8.3, 8.5
-
Run the programs and do the exercises described above
-
April 25-26: Take Quiz 5 online in Blackboard for 2 points +
5 points extra credit
-
April 27, May 2, 4: Arrays of objects
-
Topics
-
Arrays of objects
- Two-dimensional arrays
-
Command-line arguments
-
Lecture slides: LEWIS_08.ppt
-
Programs/Exercises:
-
index.java
(create methods for converting a digit into word and vice versa).
- Using two-dimensional arrays write methods for printing a matrix of integers and for transposing a matrix.
-
Implement Students.java
using an array of objects of class Student.java
(implement a method for printing students and methods for finding/printing
students by name or grade)
-
Assignments:
-
Read Sections 8.3, 8.4
-
Answer the Self-Review Questions 8.14 - 8.19
-
Do Exercise 8.5
-
Do Programming Project 8.6
-
Run the programs and do the exercises described above
-
May 9: Submit Programming
Project 6
-
May 9, 8:00am-10am: Final Exam (see Review topics and sample problems)
Programming Project 0
Note that the submission of this project is required, the following projects
will not be accepted otherwise.
Description: Install BlueJ on your computer or use it in the computer
lab. Add comment to the code of the Hello.java,
and test it with BlueJ.
Requirements and restrictions: Use multiple line comment in the
beginning of the code and write your name, e-mail address, class, and section.
Then for each line of code (inclding also the brackets) add a comment to
explain its meaning. You may also change the message that the program prints.
Format your code accordingly (see Section 1.4 - "White Space").
Submission: Submit the following files as attachments through
Blackboard Learn / CS-151-01 / Project 0:
-
The source file (Hello.java).
-
A screen copy (an image file or an MS Word file with the image included)
of the BlueJ Program window showing the Hello class inside.
-
A screen copy or a text file with the content of the BlueJ Terminal Window
showing an example run of your program.
Programming Project 1
Log on to Blackboard
Learn to see and submit the project.
Programming Project 2
Log on to Blackboard
Learn to see and submit the project.
Programming Project 3
Log on to Blackboard
Learn to see and submit the project.
Programming Project 4
Log on to Blackboard
Learn to see and submit the project.
Programming Project 5
Log on to Blackboard
Learn to see and submit the project.
Programming Project 6
Log on to Blackboard
Learn to see and submit the project.
Test 1 Review Topics
The test will be based on material from Chapters 2, 3, 5, and 6 and in
particular:
-
Boolean expressions and logical operators
-
Type conversions, casting
-
Comparing data
-
If statement and conditions. Pay special attention to the syntax (the use
of ;) and to the else clause
-
Switch statement
-
While (leading decision) loops
-
Do (trailing decision) loops
-
For loops
-
Rewriting code with different loops
-
Writing programs with simple loops
Example Problems
-
EX 6.1 - 6.8
-
Print the squares from 0 to 100 with increments of 5
-
Use user specified range and increment
-
Print the multiplication table for 9 (or for a user specified number)
Test 2 Review Topics
The test will focus on classes and objects (Chapters 4 and 7), and will
also include previous material. In particular, the following topics from
Chapters 4 and 6 will be included:
-
Class structure (instance data, methods), creating and using objects.
-
Primitive data, objects, references to objects (note that Strings are objects).
-
Encapsulation and visibility modifiers.
-
Types of methods (constructors, accessors, mutators).
-
Method parameters, local variables.
-
Static methods and static variables.
-
Method signature and method overloading.
Example Problems:
-
EX 4.5 - EX 4.8 (page 201)
-
Write a class called Wallet. It has four instance variables – singles,
fives, tens, and twenties (all int type). The class has one constructor
(which has a parameter corresponding to each instance variable), getter
and setter methods for each instance variable, and two service methods:
totalMoney, which returns the total dollar amount in the wallet, and getMoney,
which takes a dollar amount as a parameter and updates the number of singles,
fives, tens and twenties in the wallet. Write an application class that
contains the main method. In the main method create two Wallet objects,
and use the getter and setter method to transfer $30 from one of the wallets
to the other. Print the total amount of money in each wallet before and
after the transfer. Solution (extended): Wallet.java,
WalletRunner.java
Final Exam Review Topics
-
Variables types, arithmetic expressions, casting
-
If statements: condition, "else" and "else if" clauses.
-
Loops: for-loops, while-loops, do-loops, nested loops
-
Primitive data and objects: comparing, passing as parameters
-
Arrays: declaration, initialization, indexing, passing arrays as parameters
(note that arrays are objects), finding min/max element, arrays of objects
-
Using classes: creating objects, object reference variables
-
Creating classes: instance data and methods (visibility modifiers, encapsulation,
static/non-static), parameters, local variables, "this" reference
Example Problem 1: You deposit $2000 in a bank that provides 1.5%
monthly interest rate. At the end of each month after applying the interest
you withdraw $150. Write a program that prints a table showing your balance
at the end of each month for 12 months. Solution: Bank.java
Example Problem 2: Write a method that takes an array of integers
as a parameter and computes and prints the sum of the squares of its elements.
Solution: IntArray.java
Example Problem 3: Write a class called Employee that contains
three instance variables representing employee’s first name (String type),
last name (String type) and ID number (int type), a constructor assigning
values to these variables, and a toString() method that returns the employee
information. Write another class containing the main method that declares
an array of objects of class Employee with 10 elements. Initialize each
element with an Employee object created with data entered from the keyboard
by using the Scanner class. Then print the array. Solution: Employee.java,
Company.java