Category Archives: Assignment

Pi Day The Gridworld

March 13th, 2014

Screen Shot 2014-03-13 at 7.53.55 AM

Friday is Pi Day – We will have a pi-day activity
Starting today we are celebrating Pi day by writing a program to do one of the following:
1. Calculate the digits of Pi to highest possible precision
2. Illustrate how Pi works
3. Illustrate how Pi was discovered

The programs will be judge based on ingenuity and/or creativity.
NOTE: You can use online resources to help you develop your program. You can not use already written programs.
Include any links used for your resources.

Chapter 7: Inheritance – Abstract Classes

Abstract Classes

  • It represents a concept on which other classes can build their definitions.An abstract class cannot be instantiated.
  • A class derived from an abstract parent must override all of its parent’s abstract methods, or the derived class will also be considered abstract.
  • An abstract class is similar to an interface in some ways.
  • However, unlike interfaces, an abstract class can contain methods that are not abstract.
  • An abstract class can also contain data declarations other than constants.
  • A class is declared as abstract by including the abstract modifier in the class header.
  • Any class that contains one or more abstract methods must be declared as abstract.
  • In abstract classes (unlike interfaces), the abstract modifier must be applied to each abstract method.
  • A class declared as abstract does not have to contain abstract methods.
  • Abstract classes serve as placeholders in a class hierarchy.
  • If a child of an abstract class does not give a definition for every abstract method that it inherits from its parent, then the child class is also considered abstract.
  • Note that it would be a contradiction for an abstract method to be modified as final or static.
  • Because abstract methods have no implementation, an abstract static method would make no sense.

Homework:
Read pages 382 through 419 and do exercises MC 7.1 through 7.10 and SA 7.3 and 7.4

giphy

All source: Java Software Solutions by Lewis, Loftus and Cocking

Chapter 6: ArrayLists and Generic Classes NOPE

January 14th, 2014

ArrayLists and Generic Classes

Classwork:
Write a class Customer with customer number, name, address, and balance.
Write a class Clients. Clients class has an ArrayList to keep all the customers information together. This class has the following methods:
1. add – this method adds a new customer to the ArrayList
2. remove – this method removes the customer from the ArrayList
3. update – this method changes a customer’s balance.
4. getTotal – this method finds the total of all the customers balances.
5. getMaxBal – this method finds the customer with the largest balance and returns the customer object.
6. print – this method prints all the customers information.
7. sortBalance – this method creates a new ArrayList with the customers sorted by balance. This methods prints the customers in sorted order.

Write a driver class to show all the methods above.
NOTE: use generics and for-each loops

Homework: Two questions posted on edmodo.com

First Days: Shannon Entropy – Cryptography

Classwork/Assignment:

NOTE: The following assignment doesn’t require to be Object Oriented.
Generating cryptograms. A cryptogram is obtained by scrambling English text by replacing each letter with another letter. Write a program, Crypto1_YI.java to generate a random permutation of the 26 letters and use this to map letters.
NOTE: It is not necessary to be OOD
Give example: Don’t scramble punctuation or whitespace.

// DS
// ABCDEFGHIJKLMNOPQRSTUVWXYZ
// SDTVBJGXWACIYROLUQPENKMHZF

// SM
/**
[m, n, u, h, y, c, b, s, f, a, i, k, x, r, l, z, w, t, q, o, d, e, p, g, v, j]
please give an all lowercase string to scramble (any non lowercase characters will be skipped
happy make your bed day
smzzv xmiy vldt nyh hmv
*/

Entropy.
The Shannon entropy measures the information content of an input string and plays a cornerstone role in information theory and data compression.

Shannon is famous for having founded information theory.
It was proposed by Claude Shannon in 1948, borrowing upon the concept in statistical thermodynamics. Assuming each character i appears with probability p_{i}, the entropy is defined to be H = – sum p_{i} log_{2}p_{i}, where the contribution is 0 if p_{i} = 0.

Compute entropy of DNA sequence

(a) Write a program, Entropy1_YI.java to read in a ASCII text string from standard input, count the number of times each ASCII character occurs, and compute the entropy, assuming each character appears with the given probabilities.

(b) Repeat part (a) but use Unicode.(Optional)

https://www.khanacademy.org/computing/computer-science/informationtheory/moderninfotheory/v/compressioncodes

Midterm Review ArrayLists – sorts – inheritance

AP Computer Science 2013-2014
Midterm date: 1/28

Midterm review Two-review days

Look at self-review, short answers, true/false and multiple choices exercises for chapters 2 through 8.
Review the following concepts:
Recursion: easy algorithms like factorial, Fibonacci, mathematical expression, palindrome, reversing order of a string.

Searches and Sorts: non-recursive and recursive

Arrays and ArrayLists:
• ArrayLists methods
• Iteration of an ArrayList
• Generic Classes

String class and methods

Inheritance: “ is a ” concept
• Look at the Pet application on pages 401 and on.
• Inherited methods – super
• Overloading and overriding
• Shadowing
• Abstract classes

Interfaces specially Comparable
Know how to compare elements in a linked structure, arrays, arrayLists and inherited objects.

Summer Assignment 1314

Due date: September 10th, 2013

  1. It will be graded based on design and correct implementation of the specifications.
  2. It is due on September 10th, 2013.
  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. Test that all your methods work properly.