Assignments

———————————————————————————————-
October 27th, 2014

Programming Projects 5.8, and 5.9

———————————————————————————————-
October 24th, 2014

Programming Projects 5.5, 5.6 and 5.7

———————————————————————————————-
October 23rd, 2014

Classwork: Create a class Person that realizes the Measurable interface. Write a driver to test a data set of Person(s).
Homework:
Programming Projects 5.2, 5.3 and 5.4

———————————————————————————————-
October 22nd, 2014

Catch up day.

———————————————————————————————-
October 21st, 2014

Classwork:
1. What is the difference between an error and an exception?
2. What is the difference between a class and an interface?
3. Define a Java interface called Nameable. Classes that implement this interface must provide a setName method that requires a single String parameter and returns nothing, and a getName method that has no parameters and returns a String.
4. True or False? Explain.
a. A Java interface can include only abstract methods, nothing else.
b. An abstract method is a method that does not have an implementation.
c. All of the methods included in a Java interface definition must be
abstract.
d. A class that implements an interface can define only those methods
that are included in the interface.
e. Multiple classes can implement the same interface.
f. A class can implement more than one interface.
g. All classes that implement an interface must provide the exact
same definitions of the methods that are included in the interface.

Homework:
Self-review questions 5.5 and 5.6
MC questions 5.4 through 5.10
SA questions 5.3 and 5.6
Read up to page 269

———————————————————————————————-
October 20th, 2014

Classwork:
Visit edmodo.com to answer these questions.
1. Why does a3 end up with 333 and not 777?
2. Why a1 isn’t 999 after execution of ParameterTester?
3. Does a1 ever change to 999?
4. Why does a2 change to 888?
5. When does a2 change to 888?
6. Why can a2 change to a different value while a1 and a3 can’t?

Homework:
Self-review questions 5.1 through 5.4
MC questions 5.1 through 5.3
SA questions 5.1 and 5.2
Read up to page 267

———————————————————————————————-
October 17th, 2014

Classwork/Homework:
1. Use your homework as a guide to define the signature of every class’ method.
2. Draw an UML class diagram for you entire application. Make sure you follow the rules for UML.
You can use google doc drawing or just a word doc. Upload your work in edmodo.com

———————————————————————————————-
October 16th, 2014

Write the public interface for Goodies Co.

———————————————————————————————-

October 14th, 2014

Homework: Read pages 257 through 260 (Chapter 5) and work on Programming Project 5.1

———————————————————————————————-

October 13th, 2014

Class work: Submit your work in edmodo.com

1. Select a class of your choice and overload the constructor and a method. Submit also a test class to demonstrate the use of both constructors.

2. What error do you get if your overloaded constructor or method has the same signature as the original constructor or method? Based on the error given, can you deduce if overloading takes place at compilation or run time?

3. Write a method called evenlyDivisible that accepts two int parameters and returns true if the first parameter can be evenly divided by the second, or vice versa, and false if it can’t be. Return false if either parameter is zero. Overload evenlyDivisible to accept Integer parameters and have the same functionality. Include any comment you feel is appropriate.

4. Write a method called average that accepts two integer parameters and returns their average as a floating-point value. Overload the average method so that the method returns the average of three integers. Overload the average method to take four integer parameters and return their average.

Homework: Read pages 210 through 214

———————————————————————————————-
October 9th, 2014

Class work: YI_HugeInteger.java and YI_HugeIntegerDriver.java

Huge Integer Class: Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digit each. Provide methods parse, toString, add and subtract. Method parse should receive a String, extract each digit using method charAt and place the integer equivalent of each digit into the integer array. For comparing HugeInteger objects, provide the following methods:

isEqualTo, isGreaterThan, isLessThan, isGreaterThanOrEqualTo and isLessThanOrEqualTo

Each of these is a predicate method that returns true if the relationship holds between the two HugeInteger objects and returns false if the relationship does not hold. Provide a predicate method isZero. Extra credit: provide methods multiply, divide and remainder. Limit these last 3 operations by a data type int.

Homework: Read up to page 263

———————————————————————————————-

October 6th, 2014

Preparing for Chapter 4 Test on 10/8

Make sure you completed all these assignments by tomorrow:

MC questions 1 through 10 (previously assigned)
T/F questions 1 through 10 (previously assigned)
Short Answers 1 through 6 (previously assigned)
Short Answers 7 through 11 (previously assigned)
Homework: Short Answers 12 through 18, skip 15 and 17 (12, 13, 14, 16) (newly assigned)

———————————————————————————————-
October 2nd, 2014

Classwork
Visit edmodo.com to answer the following questions:

11. Objects should be self-governing. Explain.
12. What is the interface to an object?
13. What is a modifier?
14. Why might a constant be given public visibility?
15. Describe each of the following:
a. public method
b. private method
c. public variable
d. private variable
16. Why is a method invoked through (or on) a particular object? What is the exception to that rule?
17. What does it mean for a method to return a value?
18. What does the return statement do?
19. 
Is a return statement required?
20. Explain the difference between an actual parameter and a formal parameter.
21. Write a method called getFaceDown for the Die class that returns the current “face down” value of the die. Hint: On a standard die, the sum of any two opposite faces is seven.
22. In the Banking program:
a. How many Account objects are created?

b. How many arguments (actual parameters) are passed to the
withdraw method when it is invoked on the acct2 object?

c. How many arguments (actual parameters) are passed to the
addInterest method when it is invoked on the acct3 object?
23. Which of the Account class methods would you classify as accessor
methods? As mutator methods? As service methods?

Programming Assignment
Add to your test class from assignment 4.8 a feature to calculate the highest and lowest average grades of at least 5 students.

Homework
Short answers 4.7 through 4.11
MC questions 4.9 and 4.10
T/F questions 4.1 through 4.10
Chapter 4 Programming Assignment 9

———————————————————————————————-
October 1st, 2014
Classwork
Chapter 4 Programming Assignment 7

Chapter 4 Short answers 4.5 and 4.6
Chapter 4 MC questions 4.7 and 4.8

Homework
Chapter 4 Programming Assignment 8

———————————————————————————————-
September 29th, 2014

Chapter 4 – Writing Classes
Back to topics from previous lesson.

Answer the following questions in edmodo.com:
5. What is the difference between an object and a class?
6. Describe the instance data of the Die class.
7. Which of the methods defined for the Die class can change the state of a Die object-that is, which of the methods assign values to the instance data?
8. What happens when you pass an object to a print or println method?
9. What is the scope of a variable?

10. What are UML diagrams designed to do?

Classwork:
Programming Project 4.5

Homework:
Read up to page 210
MC questions 4.4 through 4.6
Short answers 4.3 and 4.4
Programming Project 4.6

———————————————————————————————-
September 26th, 2014

Classwork:
Answer the following questions in edmodo.com:
1. What is an attribute?
2. What is an operation?
3. List some attributes and operations that might be defined for a class called Book that represents a book in a library.
4. True or False? Explain.
a. We should use only classes from the Java standard class library when writing our programs—there is no need to define or use other classes.
b. An operation on an object can change the state of an object.
c. The current state of an object can affect the result of an operation on that object.
d. In Java, the state of an object is represented by its methods.

Homework:
Read up to page 205
MC questions 4.1 through 4.3
Short answers 4.1 and 4.2
Programming Projects 4.1 and 4.2

———————————————————————————————-
September 24th, 2014

FlowchartProgram.java
Write the program for this flowchart
Screen Shot 2014-09-25 at 10.30.27 AM

PartnerFlowchartProgram.java
Work with a partner to share your flowchart. In turn, your partner will share his/her flowchart with you. Both of you will write a program for the other’s flowchart. It should not be too easy or too difficult. The program should reflect the flowchart and you will be graded on how well you can implement your partner’s flowchart and how well your partner can implement your flowchart. There are two posts for your work and your partner’s work.

Programming assignment 4.3 and 4.4
———————————————————————————————-

September 23, 2014
StepsApplet,java
Design and implement an applet that draws the side view of stair steps from the lower left to the upper right.

———————————————————————————————-

September 22, 2014

Programming Exercise 3.11
Design and implement an application that plays the Hi-Lo guessing game with numbers (Listing 3.3). The program should pick a random number between 1 and 100 (inclusive), then keep asking the user to guess the number. On each guess, report to the user that he or she is correct or that the guess is high or low. Keep accepting guesses until the user guesses correctly or quits. Use a sentinel value to determine whether the user wants to quit. Count the number of guesses and report that value when the user guesses correctly. At the end of each game (by quitting or a correct guess), ask whether the user wants to play again. Keep playing games until the user chooses to stop.

———————————————————————————————-
September 18th, 2014

Programming Assignments:
1. Write a program that prints all real solutions to the quadratic equation
ax² + bx + c = 0. Read in a, b, c and use the quadratic formula. If the discriminant b² – 4ac is negative, display a message stating that there are no real solutions.
Implement a class QuadraticEquation whose constructor receives the coefficients a, b, c of the quadratic equation. Supply methods getSolution1 and getSolution2 that get the solutions, using the quadratic formula.
Supply a method

boolean hasSolutions()

that returns false if the discriminant is negative.

Homework: MC question 1-10
———————————————————————————————-

September 17th, 2014

Classwork/Homework
Design and implement an application, YI_SloptMachine.java that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side. Print a statement saying all three of the numbers are the same, or any two of the numbers are the same, when this happens. Keep playing until the user chooses to stop.
Screen Shot 2014-09-16 at 2.47.15 PM

Homework:
Short answer 3.10.
———————————————————————————————-
September 16th, 2014

Classwork/Homework
Design and implement an application that plays the rock-paper-scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, rock beats scissors, scissors beats paper, and paper beats rock. The program should randomly choose one of the three options (without revealing it), then ask for the user’s selection. At that point, the program reveals both choices and prints a statement indicating that the user won, that the computer won, or that it was a tie. Keep playing until the user chooses to stop, then print the number of user wins, losses, and ties.

Homework – Programming Project 3.3

Change the solution to the Programming Project 3.2 so that the user can enter more than one year. Let the user end the program by entering a sentinel value. Validate each input value to make sure it is greater than or equal to 1582.
———————————————————————————————-
September 15th, 2014

Classwork: using this code snippet write a program YI_minMax.java to prompt the user for three numbers and displays them in order from smallest to largest.

Classwork: Boolean expression

Class work: Programming Project 3.2
Design and implement an application that reads an integer value representing a year input by the user. The purpose of the program is to determine if the year is a leap year (and therefore has 29 days in February) in the Gregorian calendar. A year is a leap year if it is divisible by 4, unless it is also divisible by 100 but not 400. For example, the year 2003 is not a leap year, but 2004 is. The year 1900 is not a leap year because it is divisible by 100, but the year 2000 is a leap year because even though it is divisible by 100, it is also divisible by 400. Produce an error message for any input value less than 1582 (the year the Gregorian calendar was adopted).

Homework: Read pages 124 through 140, visit edomod.com and type the answers to short answers 3.1 through 3.5.

———————————————————————————————-

September 12th, 2014

Homework:
Answer the Multiple Choice questions at the end of chapter 2.

———————————————————————————————-

September 11th, 2014

The Java Language
1. What is encapsulation and what is the purpose?
2. Explain abstractions. Give an example of an abstraction.
3. Give the code to concatenate two strings “hello” and “goodbye”.
4. List the escape sequences and the meaning.
5. Write the statement to print “Hello World” including the quotes.
5. List all primitive data types you know.
6. What is the difference between a character and a string.
7. Do you need to cast when assigning a double to an integer? why or why not?
8. Do you need to cast when assigning an integer to a double? why or why not?
9. Give an example of widening and narrowing type conversion for each.
10. What is the purpose of casting when using a casting operator in the case of narrowing type conversion.
11. What does “123456789”.substring(3,6) return?
12. Write a main method that prompts the use for two numbers, x and y, and it displays it back the following format: (x,y).
13. Write a code snipped to compare two strings, s1 and s2. If s1 comes first in the lexicographic order, then it will print “move two steps forward” else “move two steps backwards.
14. What is the result of 21 % 6 when evaluated in a java expression?

Object Oriented Design
1. What are classes like?
2. What is the content of an object variable?
3. Why the “= =” cannot be used to compare objects?
4. What is an instance of a class?
5. In the following code: BankAccount myAcct = new BankAccount(); Is myAcct an object of BankAccount?
6. What is the purpose of a constructor?
7. Can you have multiple constructors?
8. What is the return type of a constructor?
9. What does the operator new do?
10. What does it mean a string object is inmutable?
11. What is a wrapper class? What is autoboxing? Give clear examples.

Homework:
Do the self-review questions at the end of the chapter.

———————————————————————————————-

September 10th, 2014

Programming Assignment:
Upgrade the Snowman applet and upload it to edmodo.com.

Screen Shot 2014-09-09 at 10.13.27 PM

Announcement: Chapter 2 Test on Friday 9/12

Homework: visit edmodo.com to answer the following questions.
1. What is the content of an object variable?
2. Write a code snipped to compare two strings, s1 and s2. If s1 comes first in the lexicographic order, then it will print “move two steps forward” else “move two steps backwards.
3. Why the “= =” cannot be used to compare objects?
4. Give an example of widening and narrowing type conversion for each.
5. What is the purpose of casting when using a casting operator in the case of narrowing type conversion.
6. What is the result of 21 % 6 when evaluated in a java expression?
7. What is the result of (double) (15/2) in a java expression?
8. What does the operator new do?
9. Write the statement to print “Hello World” including the quotes.
10. What does “123456789”.substring(3,6) return?
11. Write a main method that prompts the use for two numbers, x and y, and it displays it back the following format: (x,y).

———————————————————————————————-

September 9th, 2014

Homework:
Submit your work in edmodo.com
Short answers 6 and 7
true/false questions at the end of chapter 2

———————————————————————————————-

Java Language Review Assignment
Due date: September 9th, 2014

  1. It will be graded based on design and correct implementation of the specifications.
  2. It is due on September 9th, 2014.
  3. Attach pseudocode
  4. Attach a flowchart. Here are some basic flowhcart symbols you need to know: Screen Shot 2013-09-01 at 8.24.32 PM
  5. Implement the driver/test class.

Create class IntegerSet. Each object of the class can hold integers in the range 0 through 100. A set is represented internally as an array of booleans. Array element a[i] is true if integer i is in the set. Array element a[j] is false if integer j is not in the set. The no-argument constructor initializes a set to the so-called “empty set” (i.e., a set whose array representation contains all false values).

Provide the following methods:

1. Method unionOfIntegerSets creates a third set which is the set-theoretic union of two existing sets (i.e., an element of the third set’s array is set to true if that element is true in either or both of the existing sets; otherwise, the element of the third set is set to false).

2. Method intersectionOfIntegerSets creates a third set which is the set-theoretic intersection of two existing sets i.e., an element of the third set’s array is set to false if that element is false in either or both of the existing sets; otherwise, the element of the thirds set is set to true).

3. Method insertElement inserts a new integer k into a set (by setting a[k] to true).

4. Method deleteElement deletes integer m (by setting a[m] to false).

5. Method setPrint prints a set as a list of numbers separated by spaces. Print only those elements that are present in the set. Print — for an empty set.

6. Method isEqualTo determines if two sets are equal.

Write a program to test your IntegerSet class. Instantiate several IntegerSet objects. Include proof that all your methods work properly.

———————————————————————————————-

———————————————————————————————-

———————————————————————————————-

———————————————————————————————-

———————————————————————————————-

———————————————————————————————-