- SAVE EVERY PROGRAM YOU WRITE ON THE H (Host) DRIVE.
- Lots of 100/80/60 quizzes based on the reading assignments
- There are a few small assignments to be handed in.
- The Unit Test is worth 15% of your final mark.
- The group project worth 20% of your final mark.
- How to get an A on Programming Assignments: Program Marking Criteria
- Canadian Computing Contest
- Spring Break
- End of Term 1 and Game Due
- Watch this video: How To: Create a Simple Java Program Using Eclipse
- Debugging in Eclipse
- At HOME: Download Eclipse IDE for Java Developers
- What is a variable?
- Naming Variables
- Numerical Variable Types
- Declarations and Initialization
- Type Conversions
- Arithmetic Operators
Compile and run in Eclipse: JavaMath.java
- How to get user input from the command line
- Run this program using Eclispe: ConsoleInput.java
- Run this program using Eclispe: Greeting.java
- conditional expression operator
- enhanced for
- characters - then print an error message that says "invalid radius" and repeats the question
- a negative value - then print an error message that says "value must be positive" and repeat the question
- a value greater than 1000 - then print a message that says "wow, that is big!" and continue with the calculations.
Create an ASCII Art Sign
Practice in writing methods. Complete the assignment using the following steps. Assignment requirements must be met exactly to get full marks.
- Write a short
main()method that calls a
drawLine()method with one integer parameter. The integer is the length of the horizontal line. For example, the call
drawLine(10)would print the following output:
+----------+Test your method by calling it from
main()with various values >= 0.
- Write a method called
drawSign()that takes a string parameter and prints a box around the string. For example, the call
drawSign("Mount Douglas Secondary");would print the following output:
+-----------------------+ |Mount Douglas Secondary| +-----------------------+
drawSign()method by calling it from
main()with various strings. The
drawSign()method must call
drawLine()to draw the horizontal lines.
- Write a method called
happyBDaySign()that takes two parameters. The first parameter is a string with a person's name. The second parameter is an integer with that person's year of birth. The
happyBDaySign()method calls integer with that person's year of birth. The
drawSign()with a Happy Birthday message created from the person's name and age. For example, the call
happyBDaySign("Ada Lovelace", 1815);will call the
drawSign()method with the following string:
drawSign("Happy Birthday Ada Lovelace. You are 196 years old.");and the output would be:
+---------------------------------------------------+ |Happy Birthday Ada Lovelace. You are 196 years old.| +---------------------------------------------------+Test
happyBDaySign()by calling it from
main()with various interesting names and birth years. (Ada Lovelace is regarded as the world's first computer programmer. Look her up on Wikipedia)
- Print the code and put it in the wire inbox on my desk. You will also demonstrate your test program for Ms. Wear.
Note: This exercise is from Grade 11. The difference is I want you to use the enhanced for loop ONLY in both
findSum. You will need to use the traditional for loop when you populate the array with random numbers.
Declare a 4x4 2D array of integers. Populate the array with random
integers between (and including) 0 and 9.
Call a method named
print2DArray and pass it the above array.
The method will print the array by line as shown below:
1 2 3 4 4 3 2 1 5 6 7 8 8 7 6 5Call a method named
findSumand pass it the above array. The method will find the sum of the numbers in the array and print it.
1.2) Watch and do Defining a Class and Creating Objects in Java
1.5) Read Take Car
2) Read If You Don't Object
Object Oriented Programming Resources
Fractions can be represented as a ratio p / q where p is an integer and q is a non-zero positive integer (q > 0). Design and implement a Java class Fraction for representing such numbers. Implement the following methods:
- Fraction() - a constructor that accepts p and q, and creates a new Fraction object. Make sure that the numerator p and denominator q do not have common divisors. (Hint: Do this by calculating the greatest common divisor.)
- getNumerator() - returns the numerator
- getDenominator() - returns the denominator
- add() - accepts two fractions and returns the sum
- multiply() - accepts two fractions and returns the product
- getDouble() - returns the value of a fraction as a double
- toString() - returns a String value of the fraction in the form numerator/denominator
- What is pairs programming? How is it done? What are its benefits over individual programming?
- What is the KISS principle? How does it apply to writing programs for ICTP 12?
- What is the DRY principle? What is the WET principle? How does DRY apply to writing programs for ICTP 12?
- What is the YAGNI principle? What is the rationale behind it? How does it apply to writing programs for ICTP 12?
- What is program optimization? Should it be done early or late in software development? What are the downfalls of optimization?
Read about Ceasar Ciphers.
Write a program that creates a random Ceasar cipher (encryption code) for a
text message. The program should read a text message from a file called
It then saves the cyphertext of the message in a file called
Math.random() returns a random double between 0.0 and 1.0.
Write a program that breaks the encryption code for a Ceaser cipher message.
The program should read a cyphertext from a file called
It then displays the top 3 possible translations of the message in the console ranked first to third. The first is the top ranked solution.
Part marks will be given for translations that rank the correct solution as second or third. Read General Program Marking Criteria.
Note: solutions that take longer than 60 seconds on school computers will not be accepted.
As well as the analysis of letter frequencies, other patterns can also be detected that may help to decipher a piece of ciphertext.
The following text explains some of the clues that can be used to deduce a word or a letter in a piece of ciphertext. If you scroll further down the page, you will see a list of tables that explain letter frequencies and patterns in the English language.
Identify Common Pairs Of Letters: If the ciphertext appears to encode a message in English, but the plaintext does not reveal itself immediately, which is often the case, then focus on pairs of repeated letters. In English the most common repeated letters are ss, ee, tt, ff, ll, mm and oo. If the ciphertext contains any repeated characters, you can assume that they represent one of these.
Identify The Smallest Words First: If the ciphertext contains spaces between words, then try to identify words containing just one, two or three letters. The only one-letter words in English are a and I. The most common two-letter words are of, to, in, it, is, be, as, at, so, we, he, by, or, on, do, if, me, my, up, an, go, no, us, am. The most common three-letter words are the and and.
Tailor Made Frequency Tables: If possible, tailor the table of frequencies to the message you are trying to decipher. E.g., military messages tend to omit pronouns and articles, and the loss of words such as I, he, a and they will reduce the frequency of some of the commonest letters. If you know you are tackling a military message, you should use a frequency table generated from other military messages.
Play The Guessing Game: This can be one of the most useful skills for a cryptanalyst to employ - the ability to identify words, or even entire phrases, based on experience or sheer guesswork. Al-Khalil, an early Arabian cryptanalyst, demonstrated this talent when he cracked a Greek ciphertext. He guessed that the ciphertext began with the greeting 'In the name of God'. Having established that these letters corresponded to a specific section of ciphertext, he could use them as a crowbar to prise open the rest of the ciphertext. This is known as a crib.
Letter and word frequencies have been analysed in a number of different languages. A few of the most commonly used ones are listed below, and may help you to decipher your secret messages.
- Download Roller7.zip.
- Extract the zip file and create a new Eclipse project.
- This is a Java Applet (not an application) that was originally written to run in a website. That is why there is an html file included in the zip file. Unfortunately browsers no longer support Java Applets. You will need to run it in Eclipse.
- Execute the applet. Examine the code and figure out how it works. You will notice this is an object oriented program with a objects
- Uncomment the lines 63, 64, 82 and 83 in
RollerBallDriver.java. What happens?
- Notice the balls always bounce at a 45 degree angle. Modify
Ball.javaso that the horziontal velocity,
dx, and the vertical velocity,
dy, are not always the same. What happens to the direction(s) of the ball(s)?
- Assign a random velocity to each instance of
- Increase the maximum speed of the balls without breaking the graphical side of the program. A ball should still be animated somewhat smoothly across the screen. If you set the speed too fast, it will be drawn in one part of the screen, and then magically appear really far away on the next draw. If this happens, you max speed is too fast.
- You should start to see a bug in the program? What happens?
- Fix the bug in RollerBall that allows balls to escape the table boundaries. I consider it fixed if it can run for 5 minutes, with 10 balls, not escaping. Redrawing the table is not considered fixing the bug.
- Due Wednesday. 10/10 = fixed. 8/10 = theory about how to fix. 5/10 = no idea but tried. 0/10 = no effort.
Create a new java project. In this project, write three classes,
AddressBookTestCases. Put these classes in a
addressbookpackage (not the default package). The first
two of these classes implement the address book. The third class is a set of test cases for the
first two classes. Define the variables and methods
necessary to implement the address book described below.
OneAddress needs to be able to store
- last name,
- first name,
- street address,
- optional second line of street address,
- postal code.
setmethods for each of these and at least one constructor for the class. Also write a
toStringmethod that prints a mailing label for the address.
AddressBook needs to store a list of
addresses. It needs to be able to add and remove addresses at any
time. Include the following methods:
addAddress- Adds a new address to the address book. Use the following header:
public void addAddress(String lastName, String firstName, String address, String address2, String city, String province, Stringy country, String postalCode)
removeAddress- Removes an address from the address book given the first and last name.
locationInBook- Returns index of person with the given first and last name in the address book, or -1 if they are not in the address book.
printAddress- Prints to the console a "mailing label" for a single address given the first and last name.
printAll- Prints to the console a list of mailing labels, ordered by name. (Lastname, then firstname.)
printTable- Prints to the console a list where each line has three columns, ordered by name: last name, first name, country. The columns should all be nicely lined up.
privatemethod that sorts the ArrayList.
AddressBookTestCases class will test the
functionality above. Here is a java source file to get you started
(make sure to edit the first line to have the right
package name for your own code). The method "addToBook" in that
class adds several addresses to the book. In addition, write code (in
appropriate places... either in main(), or in other methods, as
necessary) that will do all of the following:
- Add the following address to the address book (hint: use Mount Douglas at the first name and Secondary as the last name):
Mount Douglas Secondary
3970 Gordon Head Rd
Victoria, BC, Canada, V8N 3X3
- Remove "Darth Vader" from the address book.
- Print out the list of names and countries three times: first before you've added Mount Douglas or removed Vader, second after you've added Mount Douglas but before you've removed Vader, and finally after you've added Mount Douglas and removed Vader.
- Print out the mailing label for Neal Marvin.
- Print out all of the mailing labels for all of the addresses in the address book.
- Because the list of entries in the address book is dynamic (that
is, entries can be added and removed), using an array to store your addresses will be
clumsy. When you create an array with the
newoperator, it has a fixed number of entries. Instead, use an ArrayList. Look up other methods here: ArrayList API.
- To create an ArrayList that stores OneAddresses, use the following declaration:
- You will need to sort the ArrayList using Collections.sort(). This means that OneAddress will need to implement Comparable. For more information read Object Ordering. Also read Implementing Compare To. These images offer more help: compareTo, Collections.sort.
- Design your classes before you start implementing them. You may then go back and modify your design once you're implementing and realize that you need to change your design. By "design your classes", I mean sketch out the variables and methods that each class will have, including the arguments passed and the return values, but don't write the actual code inside those methods.
- Write the purpose of each method before you write the method. That way you know what you were thinking in your design, and can use that as a reference when you're writing your code.
- Talk to other students about the approach they are going to take. Be sure to write your own code, but just talking to one another can really help in the design process.
Get the space invaders code off of the Wear_IT drive.
- Make these EASY modifications to the game:
- change the title of the main window
- change the image used for the ship
- decrease the firing interval to 300 ms
- make the ship spawn on the left side of the screen instead of in the middle
- change the number of aliens to 7 rows of 12 instead of 5 rows of 12
- change the message notification when you win and lose
- make the aliens speed up by 4% when an aliens has been killed (instead of 2%)
- Make these MEDIUM modifications to the game:
- Give the ship the ability to jump up 50 px when the up arrow is pressed. It should then fall back to the ground.
- Change the size of the game window to 1000 px wide by 1000 wide. Update the background to fit. Modify the ship so it stops moving at the edges. Modify the aliens so they change direction when they hit the new edges. Modify the shot so it is removed once it is off the bigger screen.
- If you make it this far, make these HARD modifications to the game:
- add a BombEntity that is shot from the ship when the "B" key is pressed. It kills the alien it hits and all surrounding aliens.
- get the aliens to shoot back
- None of this is for homework. However, your understanding of the code will affect which group you are put in.
- "A small graphic that can be moved independently around the screen, producing animated effects."
- Project Description
- How to Create an Jar File Using Eclipse
- Instructions for creating a web-distributable application from command line (only use if Eclipse fails).
- Resources: Free Game Graphics, Open Game Art
- Advanced Stuff: Basic Tile Based Platformer in Java, Creating a 2D Platformer game, A* Shortest Path Algorithm for Games
- You might want to consider using an online code repository like Github.
Prototype 2 Due Tuesday Oct 22: Playable game.
Final Project due Monday Oct 28: Jar file, banner, all game code and class files handed into Student Share > Wear_IT > Hand-in > CS 12 > Java Game
56 Multiple Choice Questions on everything from this unit up to and including inheritance (and some grade 11 basics!).>
Topics include: Java platform, primitive data types, casting, objects and references, methods, overloading, algorithms, arrays, String class, API, loops, conditionals, arithmetic operators, File Input/Output, Software Engineering Principles, Classes, OOP, Constructors, instances, IDE's, compareTo, toString.ArrayList.
No AWT or KeyInputHandler questions.