Thursday, December 18, 2008

Work due by 6AM tomorrow.

I'll need your work online before 6am not 6pm as I wrote on the board yesterday.

Thanks,

DF

Wednesday, December 10, 2008

Here is your final exam review sheet

Here it is: http://docs.google.com/Doc?id=dc65q8nz_355gzxpj6fx
Pretty comprehensive. Do lots of practice coding for it!

The exam is next week at 6pm in the room.

Try www.betterprogrammer.com and put your results

http://www.betterprogrammer.com and put your results on your blog. What did you think of the site?

Monday, December 8, 2008

Discussed in class 12-8-08

Monday December 8th, 2008:
  1. How do you see yourself using Java in the future?
  2. What's the future of programming in the next 10 years?
  3. Visit: http://sourceforge.net/ and download an open source project that seems interesting and utilizes Java. Please read over some of the source code and give me your brief impressions.
  4. Visit http://www.betterprogrammer.com/ and try it out! How did you do?
  5. What did you think of Scheme programming? Try it out and put your ideas on the blog.

Wednesday, November 26, 2008

Sixth Major Programming Assignment

Poker Simulator. In this assignment, you will implement a simulation of a popular casino game usually called video poker. The card deck contains 52 cards, 13 of each suit. At the beginning of the game, the deck is shuffled. You need to devise a fair method for shuffling. (It does not have to be efficient.) Then the top five cards of the deck are presented to the player. The player can reject none, some, or all of the cards. The rejected cards are replaced from the top of the deck. Now the hand is scored. Your program should pronounce it to be one of the following:

· No pair—The lowest hand, containing five separate cards that do not match up to create any of the hands below.
· One pair—Two cards of the same value, for example two queens.
· Two pairs—Two pairs, for example two queens and two 5’s.
· Three of a kind—Three cards of the same value, for example three queens.

· Straight—Five cards with consecutive values, not necessarily of the same suit, such as 4, 5, 6, 7, and 8. The ace can either precede a 2 or follow a king.
· Flush—Five cards, not necessarily in order, of the same suit.
· Full House—Three of a kind and a pair, for example three queens and two 5's
· Four of a Kind—Four cards of the same value, such as four queens.
· Straight Flush—A straight and a flush: Five cards with consecutive values of the same suit.
· Royal Flush—The best possible hand in poker. A 10, jack, queen, king, and ace, all of the same suit.

Implement a payout system! +10

Extra credit if it is a GUI +10.

Due December 5th, 2008.

December 3rd, 2008 is your fourth exam. I will post a review sheet tonight! (as promised :)

Project 7.1 in the book.

11/26/08 In class exercise review

Assignment 1:

Suppose you have a Town class that describes the demographics of small towns. The vital statistics described by this class are numberOfAdults and numberOfChildren. These vital statistics are encapsulated and not directly accessible from outside the class.

Write an initialize method that establishes initial values of instance variables. Write a simulateBirth method which simulates the birth of one child. Write a printStatistics method that prints out the current vital statistics.

Write a main method that creates a town called newHome. Then call initialize to establish initial values for newHome. Simulate the birth of a pair of twins and print out newHome's statistics.

---

Assignment 2:
Suppose you are asked to model plants using an OOP program. For each of the following plant-related entities, specifiy the most appropriate item to use for its implementation. For each entity, select one of the following: instance variable, object, method, or class.
  1. plant height
  2. sequence of activities that occur when a seed germinates
  3. an indication of whether a plant contains a vascular system
  4. an individual plant

Please list on your blog 1-4 and whether you believe each would be handled best as a(n) instance variable, object, method, or class.

----

Assignment 3:

Think of a possible "final project" that you could possibly accomplish. Please write an idea or two on your blog!

----

Assignment 4:

See how well you do on this:

http://java.sun.com/developer/Quizzes/jbasics1-1/

Educational Info

In case you are interested:

http://www.usatoday.com/news/education/2008-11-16-CCSSE_N.htm

Monday, November 24, 2008

In case you are interested...

Alan Kay thought of many ideas behind OO programming:

http://blog.ted.com/2008/03/alan_kay_on_ted.php

Read the article: "What is an algorithm"

Read the following post:

The Importance of Algorithms.


from the following great page:

http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=alg_index

I would like for you to answer the following questions on your blog:

  1. What are algorithms used for?
  2. What is a random algorithm?
  3. What is compression?
  4. What two 'real world' examples does the author give as useful algorithms? Describe them on your blog.
  5. Do you agree that studying algorithms is a useful tool for programmers and computer scientists?

Monday, November 17, 2008

Find the first 100 prime numbers...

Use loops or recursion...

With a partner!

On your blog, please respond...

Why are there so few women in computer science?

Read the article and comment on your blog.

Wednesday, November 12, 2008

Great article about recursion

Here's a great post that references one of the most important programming books, "Godel, Escher, Bach".

Everyone should read it.

Tower of Hanoi





Code from: http://weblogs.java.net/blog/mortazavi/archive/2005/08/recursive_progr.html

private void moveTower (int numDisks, int start, int end, int temp)
{
if (numDisks == 1)
moveOneDisk (start, end);

else
{
moveTower (numDisks-1, start, temp, end);
moveOneDisk (start, end);
moveTower (numDisks-1, temp, end, start);
}
}

Use Paint to explain the Tower of Hanoi

Pretend you have four disks. Show the steps to finish!

Also paste this code under the picture:

http://weblogs.java.net/blog/mortazavi/archive/2005/08/recursive_progr.html

Chapter 13

Monday, November 10, 2008

Math fun minor project!

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Taken from this website:

http://projecteuler.net/index.php?section=problems&page=1

Coding horror

Write a response to the following blog post:

http://www.codinghorror.com/blog/archives/001184.html

Do you agree with his point? Please reply on your blog.

Make sure to have read through Chapter 12 in the book.

Wednesday, November 5, 2008

How is Blackjack going?

Write one sentence on your blog with something that is going well with your Java Blackjack program.

Write one sentence on your blog with something that is not working with your Java Blackjack program.

Don't forget about your major assignments:
http://mdcjava.blogspot.com/2008/10/major-assignments-fall-2008.html

Read this...about Microsoft...

http://moishelettvin.blogspot.com/2006/11/windows-shutdown-crapfest.html

Chapter 12



Please read chapter 12.

Tuesday, October 28, 2008

Major Assignment 4 Due Friday November 7th, 2008

Exercise P12.6.
Write a program that simulates a vending machine. Products can be purchased by inserting coins with a value at least equal to the cost of the product. A user selects a product from a list of available products, adds coins, and either gets the product or gets the coins returned if insufficient money was supplied or if the product is sold out. The machine does not give change if too much money was added. Products can be restocked and money removed by an operator. Follow the design process that was described in this chapter. Your solution should include a class VendingMachine that is not coupled with the Scanner or PrintStream classes.

Here is a sample program run:
S)how products  I)nsert coin  B)uy  A)dd product  R)emove coins  Q)uit
A
Description:
Candy bar
Price:
0.55
Quantity:
10
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
A
Description:
Fruit drink
Price:
0.65
Quantity:
10
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
S
Candy bar @ $0.55
Fruit drink @ $0.65
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
C
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
C
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
A
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
B
A) Candy bar @ $0.55
B) Fruit drink @ $0.65
A
Purchased: Candy bar @ $0.55
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
D
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
B
A) Candy bar @ $0.55
B) Fruit drink @ $0.65
B
Purchased: Fruit drink @ $0.65
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
R
Removed: $1.55
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
Q
Your main class should be called VendingMachineSimulation.

Put it on your FTP space. Due Friday, November 7th, 2008.
I'd like you to continue working on the BlackJack game...that will be the next Major Assignment.

Monday, October 27, 2008

Test 3 Review

Here is your test 3 review:

click here.

Test 1 Average: 79.2777777777778
Test 2 Average: 72.8333333333333
Test 3 Average: ???

Today's review GraderProgram

1. Take three numbers 60, 70, 80 and find the average.

2. Allow the user to enter three numbers and find the average.

3. Allow the user to enter three numbers, find the average, and give back a letter grade:
90-100 : "A"
80-89 : "B"
70-79 : "C"
60-69 : "D"
0-59 : "F"

4. Allow the user to enter three numbers and find the average if the first is worth 60% and the next two are worth 40% (20% each). Give them back a letter grade according to the previous rule.

5. Allow the user to input numbers until they quit (-1). Weight the grades equally and give back a letter grade!

6. Lastly print out their scores. Here's how:

import java.io.*;

FileOutputStream writeWords2 = new FileOutputStream("output.txt");
PrintStream p1 = new PrintStream(writeWords2);
p1.print("HELLO");

Please put it on your FTP space.

Friday, October 24, 2008

I want to see how well you do with this game...

See how you do:

http://www.addictinggames.com/lightbot.html

What do you think of the game? Please post on your blog.

Wednesday, October 22, 2008

MySQL

Download MySQL here.

CREATE TABLE address_books (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15), PRIMARY KEY (phone_number));


INSERT INTO address_books (first_name,last_name,phone_number) VALUES ('David','Freer','786-877-4573')";
-------
Next, create a student database using MySQL and a table with some information.Then create a java program (using Netbeans) and show you are able to update it and delete data from the database.Work with another classmate and upload it to your FTP space. However, when you finish call me over and I'll grade it in class.

If you need numbers, you can use INT this.

Major Assignments Fall 2008

The first:
http://mdcjava.blogspot.com/2008/09/major-assignment-1-due-september-15.html

The second:
http://mdcjava.blogspot.com/2008/09/second-major-assignmentalso-please.html

The third:
http://mdcjava.blogspot.com/2008/10/third-major-project.html

The fourth:
http://mdcjava.blogspot.com/2008/10/major-assignment-4-due-wednesday.html

The fifth:
A working BlackJack game! Due Friday November 21st, 2008.

The sixth:
http://mdcjava.blogspot.com/2008/11/sixth-major-programming-assignment.html Due Friday December 5th, 2008.

The seventh:
A program of your choosing due by December 17th, 2008. Email me with an outline of your project by December 12th, 2008. Make it something you are interested in but at the same time a project that you can complete!

Monday, October 20, 2008

Cool video

http://netbeans.tv/interviews/James-Gosling-on-Ten-Years-of-NetBeans-395/

CoffeeShop and Food classes

10/20/2008 minor project:

Today you will need to make a CoffeeShop class:
//Address
//Manager's name
//An arraylist of food


Food class:
//Price of food
//Description of food
//Quantity
//Make a constructor!
//Create a default constructor!


Within the main:
//The user should be able to make the CoffeeShop...
//The user should be able to enter food into the CoffeeShop (using an arraylist)
//The user to be able to check what's inside the CoffeeShop!

Please upload this minor project to your FTP space ASAP! Also don't forget about your third major project from the book using inheritance!

Wednesday, October 15, 2008

Third Major Project

This is a fairly easy question straight from the book:

P10.6 from page 493

Please have it on the FTP space by next Tuesday 10/21 at midnight.

If you have any other work, please put it online and let me know that you uploaded it.

Write a superclass Worker and subclasses HourlyWorker and SalariedWorker. Every worker has a name and a salary rate. Write a method computePay(int hours) that computes the weekly pay for every worker. An hourly worker gets paid the hourly wage for the actual number of hours worked, if hours is at most 40. If the hourly worker worked more than 40 hours, the excess is paid at time and a half. The salaried worker gets paid the hourly wage for 40 hours, no matter what the actual number of hours is. Supply a test program that uses polymorphism to test these classes and methods.

Use the following class as your tester class: /**
This class tests class Worker and its subclasses.
*/
public class WorkerTester
{
public static void main(String[] args)
{
Worker s = new SalariedWorker(''Sally'', 40);
Worker h = new HourlyWorker(''Harry'', 40);
System.out.println(s.computePay(30));
System.out.println(''Expected: 1600'');
System.out.println(h.computePay(30));
System.out.println(''Expected: 1200'');
System.out.println(s.computePay(50));
System.out.println(''Expected: 1600'');
System.out.println(h.computePay(50));
System.out.println(''Expected: 2200'');
}
}

Thursday, October 9, 2008

Minor Project

For a minor project, I would like everyone to answer Exercise P7.8. and put it on your FTP space by next Tuesday.

Write a program that reads a sequence of integers into an array and that computes the alternating sum of all elements in the array. For example, if the program is executed with the input data
then it computes

Use the following class in your solution:
/**
This class computes the alternating sum
of a set of data values.
*/
public class DataSet
{
/**
Constructs an empty data set.
*/
public DataSet()
{
final int DATA_LENGTH = 100;
data = new double[DATA_LENGTH];
dataSize = 0;
}

/**
Adds a data value to the data set.
@param x a data value
*/
public void add(double x)
{
if (dataSize >= data.length)
{
// make a new array of twice the size
double[] newData = new double[2 * data.length];
// copy over all elements from data to newData
System.arraycopy(data, 0, newData, 0, data.length);
// abandon the old array and store in data
// a reference to the new array
data = newData;
}
data[dataSize] = x;
dataSize++;
}

/**
Gets the alternating sum of the added data.
@return sum the sum of the alternating data or 0 if no data has been added
*/
public double alternatingSum()
{
. . .
}
private double[] data;
private int dataSize;
}

Use the following class as your tester class:
/**
This program calculates an alternating sum.
*/
public class AlternatingSumTester
{
public static void main(String[] args)
{
DataSet data = new DataSet();

data.add(1);
data.add(4);
data.add(9);
data.add(16);
data.add(9);
data.add(7);
data.add(4);
data.add(9);
data.add(11);

double sum = data.alternatingSum();
System.out.println("Alternating Sum = " + sum);
System.out.println("Expected: -2");
}
}

Monday, October 6, 2008

Static method practice in class

  1. Make a static method that takes in two numbers and multiples them and returns the result. Call it multiplier(int x, int y)!
  2. Make a static method that takes in two integers and returns the lower of the two
    call it findMinimum()
    print out the results!
  3. Make a static method, call it dividerOfTwoNumbers(int x, int y){ }
    Ask the user for two numbers. Divide the first number by the second number IF the second number is not zero.
    If they enter a zero, tell them: "You fool! You can't divide by zero!"

Wednesday, October 1, 2008

Test 2 Review

Click here for the test 2 review.

Pseudocode to do Blackjack

What would you need to make a BlackJack program?

What classes? Within those classes, what attributes and methods would you need?

What's the input? What's the output?

Let's start by writing the pseudocode on your blog...

You can win an iPod!

Miami Dade is giving away an iPod!

Wednesday, September 24, 2008

For fun and for your blog

You can read this for fun:
Now he works for Google. He's not too fond of some of his experiences at Microsoft...

_____________________________________________________

Paul Graham is a great thinker when it comes to starting new businesses. Read this article and explain why you think there aren't "more Googles."

Put your answer on your blog. You may be brief. It will count for towards your blog grade.

Second Major Assignment...also please upload your First Assignment

Please upload your first major assignment (BankAccount and LetterPrinter) to your FTP space as soon as you can. I'd rather if we kept all the assignments in the same place.

Your second major assignment is as follows:You are going to design a class for a business of your choosing. You need to keep track of at least four attributes.

You will need at least two other methods in addition to the necessary getters and setters.

After you create your class, make three objects and store them in an array of that type.

You can hard code the business testing info into the main.

But if you use Scanner to ask the user what to change, you can get 20 extra points on the assignment!

Here's an example, you will need to pick another business:

class LawFirm
{

//typeOfLaw, billableHours, nameOfLawFirm, costPerHour

//+20
//constructors
//+20
//methods: calculateTotalCost, returnMessageAboutFirm
//+30
}

class LawFirmTester
{

//create an array of 3 LawFirm objects
//+20
//display names of law firms and allow user to enter a number to learn more information about each firm
//+10
//allow the user to update the information about the firms- things do change.
//+20
}

The number of points are commented above.

Due Wednesday October 1st on your FTP space.

LoveTester

Using a Java GUI evaluate three pieces of information from Person A and three pieces of information from Person B.

Determine if they are a good match and output it to the GUI!It doesn't have to be serious.Minor project grade.

Work with someone from class if you wish.

Old Burgers

http://bestwellnessconsultant.com/2008/09/23/1996-mcdonalds-hamburger-karen-hanrahan-best-of-mother-earth.aspx

Wednesday, September 17, 2008

Test 1 Information

These tutorials from Sun are worth reading in addition to the book.

This developer uses these 15 exercises to master a language.

Try as many questions as you can from the Big Java book. Also read the first five chapters.

Here's a review for the first test next week.

Test 1 will be on September 23th.

Project 1 will be due on the same day. Bring in your program 1 code on a flash drive on Monday.

Coding done in class September 17th, 2008

public class HelloWorld //class designed to print hello world!
{
public static void main(String [] args)
{ //main method needed to run java application
System.out.println("Hello World!");
//syntax to print "Hello World!"
//while loop
//for loop
int counter = 0;
while(counter <= 10)
{
System.out.println(counter);
counter += 2; //the shortcut for counter = counter + 2;
}

for(int i = 100; i > 0; i --)
{
System.out.println(i);
if(i % 25 == 0){
System.out.println(i + " THIS IS A SPECIAL NUMBER!");
}

}

for(int i = 200; i > 0; i --)
{
//System.out.println(i);
if(i % 3 == 0 || i % 7 ==0 ){
System.out.println(i + " THIS IS A SPECIAL NUMBER 3 and 7");
}

}

} //Closing curly brackets /* hello */


} //closing curly brackets

1. Write a program to display "Hello World"
2. Write a program that loops to ten from 0 by 2 and prints out the result!
3. Add a for loop that counts down from 100 to 0 by one! Print out the results!
4. Within the previous loop, if a number is divisible by 25 evenly
output THIS IS A SPECIAL NUMBER!! %
5. Count down from 200 by 1 and find out if a number is divisible evenly by 3 and 7 together.
If it is print out a message "This number is divisible by 3 and 7!"
6. Start Netbeans and make a class for a student. Keep track of the GPA and Name. Provide getters,
setters, and a constructor! Call this class student.
7. Test program with main method by passing in a student
named "Jose" with a GPA of 3.5.
8. Make an array of 4 students and give them whatever info you like.
9. Print out the information in the array!
10. Ask user to enter a student name and GPA and make a student object!

Monday, September 15, 2008

If you have access...

If you purchased access to the online materials with the book publisher, here is the link to access the course.

The assignment will be due on the day of the first exam, next Monday. :)

Chapter 4 and Chapter 5 Presentations

Chapter 4




Chapter 5

Allow the user to update a vending machine

Ask a user if they want to update the stock in a vending machine. Have them continue updating either the price or quantity until they say they are ready to quit.

This will use looping, variables, user input and output, and arrays possibly.

Monday, September 8, 2008

Major Assignment 1 Due September 15, 2008

These questions are taken from the Big Java book !

Program A:
Provide a class for authoring a simple letter. In the constructor, supply the names of the sender and the recipient:

public Letter(String from, String to)

Supply a method

public void addLine(String line)

to add a line of text to the body of the letter.

Supply a method

public String getText()

that returns the entire text of the letter. The text has the form:

Dear recipient name :
blank line
first line of the body
second line of the body
. . .
last line of the body
blank line
Sincerely,
blank line
sender name

Also supply a program LetterPrinter that prints this letter.

Dear John:

I am sorry we must part.
I wish you all the best.

Sincerely,

Mary

Construct an object of the Letter class and call addLine twice.

Hints: (1) Use the concat method to form a longer string from two shorter strings. (2) The special string “\n” represents a new line. For example, the statement

body = body.concat(''Sincerely,'').concat(''\n'');

You may also use the plus sign + to add two Strings together.

adds a line containing the string “Sincerely” to the body.

Complete the following class in your solution:

/**
This class models a simple letter.
*/
public class Letter
{
/**
Constructs a letter with a given sender and recipient.
@param from the sender
@param to the recipient
*/
public Letter(String from, String to)
{
. . .
}

/**
Adds a line to the body of this letter.
*/
public void addLine(String line)
{
. . .
}

/**
Gets the text of this letter.
*/
public String getText()
{
. . .
}
private String sender;
private String recipient;
private String body;
}


Program B:
You are to create a BankAccount class with the following capabilities. The bank will be charging a fee for every deposit and withdrawal. Supply a mechanism for setting the fee and modify the deposit and withdraw methods so that the fee is levied. Test your resulting class and check that the fee is computed correctly.

The bank will allow a fixed number of free transactions (7 deposits or withdrawals) every month, and charge for transactions exceeding the free allotment. The charge is not levied immediately but at the end of the month.

Supply a new method deductMonthlyCharge to the BankAccount class that deducts the monthly charge and resets the transaction count.

Produce a test program that verifies that the fees are calculated correctly over several months.

Five bonus points if you enable user input for each program. The input will be used to create the objects.

Five more bonus points if Program B continues to loop until user chooses to Quit.

Zip up both files as Netbeans projects.

Find an article about something that interests you...

Write a very brief summary about an article that interests you.

September 8, 2008

Write a guessing game with Java where the user guesses a number between one and 100 and you give tips based on how close or far they are. If they are 20+ digits away you can laugh at them! If they are within 10-20, say they are within a decent range, otherwise say they are getting closer!

You may work with a classmate or two or by yourself.

When you are finished you may add the random number ability:

int ranNumber = (int)(Math.random()*100);

if(ranNumber > 50)
{
System.out.println(ranNumber + " is greater than 50");

}
else if(ranNumber > 25)
{
System.out.println(ranNumber + " is greater than 25");
}
else
{
System.out.println("Your number sucks!");
}

Chapter 1 and Chapter two

Chapter 1

Chapter 1


Chapter 2

Wednesday, September 3, 2008

Please give me your blog info here!

First Post: What are your expectations for the class?

Just briefly let me know what your expectations are for this class!

Client.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package bankaccount;

/**
*
* @author dfreer
*/
public class Client {
//Client properties
private String firstName;
private String lastName;
private double balance;
private int socialSecurity;

//methods for the Client
public String returnName()
{
return firstName + lastName;
}
public double getBalance(){
if(balance > 0)
return balance;
else
return -9999;
}

public void deposit(double amt)
{
balance = balance + amt;
}
//this is the constructor for the client object
public Client(String fn, String ln, double b, int ss){
firstName = fn;
lastName = ln;
balance = b;
socialSecurity = ss;
}

public static void main (String [] args)
{
Client ourFirstClient = new Client("Dwyane", "Wade", 6787456.24, 123456798);
//we make an object of Client for Dwyane Wade and return his balance
System.out.println(ourFirstClient.getBalance());
//6787456.24 is expected
ourFirstClient.deposit(1000000);
System.out.println(ourFirstClient.getBalance());
//boolean a = true;
//add to the constructor an address, preferred customer capability,
//add a method to withdraw money but do not let customer withdraw more than they
//have
}

}

Wednesday, August 27, 2008

First minor assignment

Continuing the LunchCart class:

public class LunchCart
{
//properties of a LunchCart
private int num_Sandwiches;
private int num_Drinks;
private double price_of_sandwich;
private double price_of_Drinks;
private double total_value_of_sandwiches;
private double total_value_of_Drinks;

//setter methods for the LunchCart
public void setNumSandwiches(int x)
{
num_Sandwiches = x;
}

//getter methods for the LunchCart
public int getNumSandwiches()
{
return num_Sandwiches;
}

//setter method!
public void setNumDrinks(int y)
{
num_Drinks = y;
}


//getter method!
public int getNumDrinks()
{
return num_Drinks;
}

public static void main(String [] args)
{
LunchCart thisismylunchcart = new LunchCart();
thisismylunchcart.setNumSandwiches(55);
System.out.println(thisismylunchcart.getNumSandwiches());
thisismylunchcart.setNumDrinks(15);
System.out.println(thisismylunchcart.getNumDrinks());

}
}



Add the ability to set the other variables and calculate the value of the sandwiches and the value of the drinks.

Finish this assignment by next class. To do this, you'll most likely need to install Netbeans.

Here is how to install Java to use the command line.

Print out the code before next class. Even if you don't get all the getter and setter methods or calculations, print out what you have. This will be the last and only code that you have to print out. Usually you'll put it on an FTP server.

Monday, July 28, 2008

Minimum Fun!

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package minimumfun;

/**
*
* @author dfreer
*/
public class Main {


public static int calcMinimum(int [] a, int counter, int minimum)
{
if(counter == a.length-1)
return minimum;
else
{
if(a[counter] > minimum)
{
return calcMinimum(a, ++counter, a[counter]);
}
return calcMinimum(a, ++counter, minimum);
}
}

public static int minimum(int [] a)
{
int minimum = a[0];
return calcMinimum(a, 0, minimum);
}

public static void main(String [] args)
{
int [] b = {3,4,5,6,2,5};
System.out.println(minimum(b));
}
}

Pseudocode

package recursion;

/**
*
* @author dfreer
*/
public class SmallestNumber {
//How are we going to use recursion to figure out the smallest number???


//take in an array of integers
public static int findSmallest(int [] a)
{
//call another method with a counter
return findSmallestRecursively(a, 0);

//return smallest number (int)
}

public static int findSmallestRecursively(int [] a, int counter)
{
//base case
//if we've reached the end of the array, stop! return minimum!

//if statement to determine whether next number is smaller or larger

//keep track of the smallest number using a variable (int)

//call findSmallestRecursively from itself!! (this is what makes recursion)
//within the recursive call increment counter!
}

public static void main(String []args)
{
//call the first method!
}

Final Exam Review

Click here.

It will be 50% conceptual and 50% coding. The coding will be similar to the exam 4's.

8 people have A's after last test.

Here's the grades.

On your blog

Please write about the relationship between data structures and algorithms.

What is the difference between a stack and a queue?

Pick two sorting algorithms and explain how they work.

Chapter 15

Click here for Chapter 15 presentation.

Chapter 14 presentation.

http://www.cs.oswego.edu/~mohammad/classes/csc241/samples/sort/Sort2-E.html

Final Major Project

What are you working on or planning to do for your last project? Major project 5.

Please post this on your blog.

Monday, July 21, 2008

Final project

July 30, 2008

For the final project, be creative and think of an application or game that interests you. It can be done with Netbeans as a GUI or as a console based program.

I'm not asking for anything in particular but it should be along the lines that we've done in class. A program that outputs "Hello World!" won't cut it.

So it could be related to business or gaming or personal interests. 30% of the grade will be for creativity, 50% if it runs, and 20% if it does what it says it does!

Email me if you need some ideas. You can work with someone else in the class as well.

Second blog for today: Using recursion....

How could you use recursion to find the smallest value in an array? Don't write out Java code, just write out the pseudocode.

Tower of Hanoi Code!!!

class hanoi
{
public static void main (String args[])
{

int numdisks = 3;
H_dohanoi(numdisks, 3, 1, 2);
System.exit(0);
}

static void H_dohanoi(int n, int t, int f, int u)
{
if (n > 0) {
H_dohanoi(n-1, u, f, t);
H_moveit(f, t);
H_dohanoi(n-1, t, u, f);
}
}

static void H_moveit(int from, int to)
{
System.out.print("move ");
System.out.print(from);
System.out.print(" --> ");
System.out.println(to);
}
}

Try running it with 6 pegs!

First blog post: Use paint to describe the steps in solving the Tower of Hanoi

Use three disks and show where everything is going!

Recursion

July 21st, 2008.

Tonight we will be learning recursion. The test will be postponed until Wednesday.

Wednesday, July 16, 2008

Test Four Review

Unlike last test which was multiple choice and had no coding, this test will be more like the first two tests and have actual coding! Here's a review with sample questions.

Monday, July 14, 2008

Where can you find code to read? Sourceforge.net!

Check out this cool clone Civilization (one of my favorite games of all time) http://sourceforge.net/projects/freecol/

Here's a direct link to the download.

I'd recommend downloading source code from different projects and reading through them. As you get to be a better programmer you can join projects. This looks very good on a resume!

http://sourceforge.net/

Blog reaction:

I'd like you to pick another project using Java (search for Java), download it, and check out the source code. Put your reactions to the site (http://sourceforge.net/) and the code you downloaded on your blog.

Perfect Numbers and Prime Numbers! (Minor Project)

Please implement this method to determine whether a number is PERFECT!

For example: 6 is a perfect number because 6 = 1 + 2 + 3 (1, 2, 3 are divisors of 6)
28 is also a perfect number: 28 = 1 + 2 + 4 + 7 + 14

Make your method static and test it!

You need th % modulus operator to make this work.

The second part is to find all the prime numbers up to a certain number. For instance if a user enters in 5, you will find all the prime numbers up to 5. Would 5be included? Yes! It is prime. 1 is not prime. Create a new static method to determine all the prime numbers up to that point.

Here are some notes on the questions. Pseduocode to turn into code.

Due Friday July 18th, 2008.

BetterProgrammer.com

http://www.betterprogrammer.com/

Using Netbeans try this four problems. Save your work in Netbeans and comment your thought process. Even if you don't know how to do something, try your best to use the Internet to figure out the answer!

Chapter 12

Wednesday, July 9, 2008

In class individual exercise

"CGS 1060 Grader" Program

Input:

  1. Enter your objective test scores, -1 to stop.
  2. Enter your project scores, -1 to stop.
  3. Enter your performance scores, -1 to stop.

Output:

Letter grade (A-F)

Rules:

  • First average the performance tests, objective tests, and project scores.
  • Objective tests are worth 20% of the final grade.
  • Performance tests are worth 60% of the final grade.
  • Project grades are worth 20% of the final grade.
  • A = 100-90
  • B = 80-89
  • C=70-79
  • D=60-69
  • F=0-59
  • There are at most five objective tests, five projects, and four performance exams.

Blog post

Pretend your friend is a Java programmer who uses Netbeans. Explain to them how to connect a MySQL database to Java using Netbeans. What should they do?

Be methodical with the steps.

Monday, July 7, 2008

Major Assignment 4... Due July 14, 2008

Major Assignment 4 is related to Major Assignment 2.

Using the business you worked with in the second assignment, you are going to create a GUI using Netbeans.

The user must be able to keep track of certain information about the business. After the user enters the information and clicks on the "Create Button" an object of that type must be created. For example, if you did a pre-school business by clicking on "Create Classroom" you would have made a classroom with a teacher, a certain number of students, a time, etc.

Save the object in an ArrayList. For instance with the previous example, we will end up with an ArrayList of Pre-school classrooms.

While working on love-tester...

I'll call you up to the front of the room and go over all the grades I have for you so far and look at your GPA.

If you did the extra questions from the book, let me know. This will be for feedback as well.

DF

Chapter 11

Chapter 11

Chapter 12

Chapter 12 PowerPoint

Wednesday, July 2, 2008

Minor Assignment

"Love Tester!" Show me this July 7, 2008.

Using a Java GUI evaluate three pieces of information from Person A and three pieces of information from Person B.

Determine if they are a good match and output it to the GUI!

It doesn't have to be serious.

Minor project grade. Work with someone from class if you wish.

Minor Project: Student database

Create a student database using MySQL and a table with some information.

Then create a java program (using Netbeans) and show you are able to update it and delete data from the database.

Work with another classmate and upload it to your FTP space. However, when you finish call me over and I'll grade it in class.

To alter the table.

MySQL - GUI Example

Mysql

http://dev.mysql.com/downloads/mysql/5.0.html#win32

Creating tables

http://mdcjava.blogspot.com/2008/04/creating-tables-within-mysql.html

Wednesday, June 25, 2008

Superclass and subclass example in class

Write a java program to create a superclass martial arts student. What will a student be able to do after the first class?

Next you will have a subclass Ninja which will extend from the martial arts student. A ninja will be able to do anything the student can do but he can do much more! Add behavior that a ninja could do that a beginning student could not.

Write a main method to show these super and sub classes in action. Try running methods unique to one on the other!

Check out this thread about an IDE debate

See what other programmers have to say. Just read the comments about the different development environments.

I would like you to comment on this blog post. Please give a summary of what the author is saying on your own blog.

Review for third test

This test is loaded with vocabulary and multiple choice questions. Inheritance, interfaces....Read chapter 8,9,10 before class. Some things you may have to read over a few times.

Here's some questions:

http://docs.google.com/Doc?id=dc65q8nz_790qqxdmvfx

Monday, June 23, 2008

Add some points to your previous test

For every programming exercise you do from chapter 6-10 you can get 3 points on your test for a maximum of 9.

Email me and upload it to the FTP server. Deadline next Monday June 30, 2008.

Email me for your grades.

Wednesday, June 18, 2008

A BlackJack program designed by you and a partner

Major Assignment 3
Next major project Due Friday 6/27/08 by the start of class: Design a BlackJack program with another student! Send me a note with who you are working with (or if you choose to work alone).

Use a class Card that randomly assigns the card as either a 2-10 or a Jack, Queen, King, or Ace. Methods should be public int returnValue()will return the int value of a card. You may assume an Ace is an 11 but extra credit (+5) is available if you determine whether it should be a 1 or an 11!

public String returnTypeOfCard() will return the full name of the card.

class BlackJack is where things get interesting...how are you going to represent the game?
What methods are needed to check the sum? What other methods are needed? If the user asks to stop hitting, will the computer dealer want to hit again (Hint, under 17 he will!). Just ignore the suits for now.

It must be done in an object oriented fashion (this is Java, not C). Use arrays of Cards in class BlackJack.

class BlackJackTester() will play the game until the user gives up!

Due Wednesday before 6:00 pm.

Upload it your FTP space.
I'd like both members of the group to upload the .class and .java files to their FTP space.

ftp://davidcfreer.com

Fun little diversion

Check out this cool game written in Java. It can be challenging!

Today's minor assignment

Create a program with a Person class where the user enters in an ArrayList with 5 Persons. A Person is considered to have a name and an age.

Input: 5 Names, 5 ages

Output: The 5 Person objects (names and ages).

Comment each line of your program, explaining what each line is doing!

Upload to FTP space at end of class.

Monday, June 16, 2008

In your own words to define...

Interface, abstract class and inner class.

Pick one; find formula on Internet; do it with Java (static method)

//public static double sphereVolume(double r)

//public static double cylinderSurface(double r, double h)

//public static double coneVolume(double r, double h)

!!!

Wednesday, June 4, 2008

Second major assignment

I hope everyone has read up through chapter 7 in the book. Practice as many exercises as you can from the end of the chapter!

Your second major assignment is as follows:

You are going to design a class for any business of your choosing. You need to keep track of at least four pertinent attributes. You will need at least two other methods in addition to the necessary getters and setters. Create three objects and store them in an array of that type.

You can hard code the business testing info into the main. But if you use Scanner to ask the user what to change, you can get 20 extra points on the assignment!

Here's an example, you need to pick another business:


class LawFirm
{
//typeOfLaw, billableHours, nameOfLawFirm, costPerHour
//+20
//constructors
//+20
//methods: calculateTotalCost, returnMessageAboutFirm
//+30
}

class LawFirmTester
{
//create an array of 3 LawFirm objects
//+20
//display names of law firms and allow user to enter a number to learn more information about each firm
//+10
//allow the user to update the information about the firms- things do change.
//+20
}

}


The number of points are commented above.

Due June 15th, 2008 at midnight! Use netbeans and upload everything in a zip file to your FTP space!

DF

Nursery Program!

Today you are going to create a Plant class with the following information:

Cost

Name

Size

Quantity of plants

The nursery will create an array of plants (let's say they have 5 different types of plants).

The nursery class should keep track of:

Money taken in

Money spent on supplies

Plants on hand

The user should be able to update information about the plants and money that is coming in or out! Let's say the user should be able to update the quantity of certain plants available and the amount of money money taken in to the company!

Here's one way to loop using a trivial example:

Scanner a = new Scanner(System.in);

System.out.println("What would you like to do? [Quit] or [Deposit] $1000");

String ans = a.nextLine();

double deposit = 0;

while(!ans.equals("Quit")) //loop is going the basis

{

if(ans.equals("Deposit"))

{

deposit += 1000.0;

}

System.out.println("What would you like to do? [Quit] or [Deposit] $1000");

ans = a.nextLine();

}

System.out.println(deposit);

Find an interesting article from Slashdot.org

Write a brief summary about the article and post a link to the article on your blog!

Slashdot.org

Monday, June 2, 2008

first assignment of the day

/**
*
* @author dfreer
*/
public class NumberTester {
//Write an if statement to determine if a number is greater than fifty!
//Write the if statement within a public method to be run from a main

//if the number entered is > 50, give the user a message of congrats!!

//main to test it out!

}

Sunday, May 25, 2008

FTP access

Class, I made your FTP accounts.

The FTP service is ftp://davidcfreer.com


Username is your first name:

(Davids need to put David plus the first letter of your last name. Example: David Smith is DavidS)

Password is your MDC student ID.

If you have no idea how to use FTP, I will teach you on Wednesday before our test.

Wednesday, May 21, 2008

Major Assignment 1: Due Friday May 30th, 2008

Program A:
Provide a class for authoring a simple letter. In the constructor, supply the names of the sender and the recipient:

public Letter(String from, String to)

Supply a method

public void addLine(String line)

to add a line of text to the body of the letter.

Supply a method

public String getText()

that returns the entire text of the letter. The text has the form:

Dear recipient name :
blank line
first line of the body
second line of the body
. . .
last line of the body
blank line
Sincerely,
blank line
sender name

Also supply a program LetterPrinter that prints this letter.

Dear John:

I am sorry we must part.
I wish you all the best.

Sincerely,

Mary

Construct an object of the Letter class and call addLine twice.

Hints: (1) Use the concat method to form a longer string from two shorter strings. (2) The special string “\n” represents a new line. For example, the statement

body = body.concat(''Sincerely,'').concat(''\n'');

You may also use the plus sign + to add two Strings together.

adds a line containing the string “Sincerely” to the body.

Complete the following class in your solution:

/**
This class models a simple letter.
*/
public class Letter
{
/**
Constructs a letter with a given sender and recipient.
@param from the sender
@param to the recipient
*/
public Letter(String from, String to)
{
. . .
}

/**
Adds a line to the body of this letter.
*/
public void addLine(String line)
{
. . .
}

/**
Gets the text of this letter.
*/
public String getText()
{
. . .
}
private String sender;
private String recipient;
private String body;
}


Program B:
You are to create a BankAccount class with the following capabilities. The bank will be charging a fee for every deposit and withdrawal. Supply a mechanism for setting the fee and modify the deposit and withdraw methods so that the fee is levied. Test your resulting class and check that the fee is computed correctly.

The bank will allow a fixed number of free transactions (7 deposits or withdrawals) every month, and charge for transactions exceeding the free allotment. The charge is not levied immediately but at the end of the month.

Supply a new method deductMonthlyCharge to the BankAccount class that deducts the monthly charge and resets the transaction count.

Produce a test program that verifies that the fees are calculated correctly over several months.

Five bonus points if you enable user input for each program. The input will be used to create the objects.

Five more bonus points if Program B continues to loop until user chooses to Quit.

---

Turn in your source code by Tuesday, either by (A.) zipping it up and sending it to me via email (B.) zipping it up, bringing it in via flash drive and sending it to me via the MDC network (C.) http://www.megafileupload.com/ or similar and a link.


Don't forget to comment throughout your program. Refer to inputs and outputs.

If you need help, send me any questions.

DF

Email me your programs before midnight Friday May 30th, 2008 or bring it in on a flash drive on May 28th 2008.

Find an article that interests you and write a few ideas about it

http://reddit.com/r/programming/
Put on your blog or Google Documents!

In class program

Create program to add two numbers entered by the user, find average of three numbers entered by the user, enter a number and find the square root.

Do this with another classmate if you wish.

Here is the code to use Scanner!

http://docs.google.com/Doc?id=dc65q8nz_651hq5rjjgc

Nursery Project

So far you should have a list of methods and attributes a nursery might need to take care of. Also you should have getters and setters for a Nursery class.

Now I would like for you to work on a Plant class.

What attributes will you need to keep track of with this class? How will it be used by the Nursery class?

BlueJ is a good IDE for a project like this.

Link to study for the test.

Your first test is next Monday.

Here's your review sheet.

You'll notice that I put a link to this review sheet under the "Links" section of the blog. It will be there all semester! Before every test I will give you a comprehensive review for the test.

Monday, May 19, 2008

Student Example from BlueJ

www.davidcfreer.com/~David/Student.zip

Download this and save it on your flash drive

Click here and download it on your flash drive.

Install Netbeans 6.1 at home.

Download BlueJ here.

Install it at home.

This is how to install Java to run it from the command line!

Wednesday, May 14, 2008

First Homework

Put answers on blog or Google document before next class (Monday). Questions on page 74.

Exercise R2.1.
Explain the difference between an object and an object reference.

Exercise R2.2.
Explain the difference between an object and an object variable.

Exercise R2.3.
Explain the difference between an object and a class.

Exercise R2.4.
Give the Java code for constructing an object of class Rectangle, and for declaring an object variable of class Rectangle.

Exercise R2.5.
Explain the difference between the = symbol in Java and in mathematics.

Exercise R2.6.
Uninitialized variables can be a serious problem. Should you always initialize every int or double variable with zero? Explain the advantages and disadvantages of such a strategy.

Exercise R2.7.
Give Java code to construct the following objects:
(a)
A rectangle with center (100, 100) and all side lengths equal to 50
(b)
A string “Hello, Dave!”
Create objects, not object variables.

Reaction to this quote

"Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do." - Donald Knuth

Think about all the attributes and methods a plant nursery would need

OO ... Object oriented.

Most important attributes and methods a plant nursery would have.

Class PlantNursery

Attributes: (String, int, or double)
cost : double

Methods:

Monday, May 12, 2008

Two assignments

Send me an email to
david.freer@gmail.com

  1. with the information whether or not you have the book
  2. what is the URL to your blog.

Use the email account that you use the most.

To install bluej

Click here and download it.

Here is the API for Java from Sun.

Welcome to Java and Object Oriented Programming

We are going to have a great semester!

First blog post: What do you hope to get out of COP2800 Introduction to Java?

Your first assignment is to read this article about classes and objects.

Thursday, May 1, 2008

Jung Typology Test

Try this out.

See what you get.

Tuesday, April 29, 2008

Java Final Exam!

Topics:
  • Recursion
  • ArrayList
  • Strings
  • double vs. int
  • Writing methods.

The coding part will be the math game. You can do it ahead of time and put it on your FTP space. It's more accurate than hand-coding it on paper.

It won't take too long! I would like to spend time in class discussing queues, stacks, and other data structures...

Deadline for final project: Friday.

Assignments

http://mdcjava.blogspot.com/search?q=assignment

Plus blackjack!

Write a blog post about the status of your final project!

Please write a brief blog post about everything that you've done so far towards your final project (picked by you!).

See how well you do on this test.

Remember the different certifications available?

Check out these 10 questions from Sun.

How did you do?

What is going on here?

What is all this about? Comment on your blog.

Also please read the single most important thing you must do to improve your programming career.

Chapter 14



Here is the source code for the examples from class:
http://www.davidcfreer.com/~David/ch14wiley.zip

Chapter 15 Slides



http://www.davidcfreer.com/~David/ch15wiley.zip

Using three IDEs (and Notepad) to create Java programs.

Using simply notepad (and without looking on the Internet) create a program that will keep track of a car's mileage, mph, gas in the tank, and the known sum spent on gas. You will create methods to simulate driving a certain distance. The program must calculate the miles driven and the gas left in the tank. The same method should also allow for the user to enter in the price of gas, which will be kept in a variable.

Download this. Open it with BlueJ.

Create a class to keep track of zoo animals. Use Netbeans to enter in their information. Store the info in an ArrayList when a button is clicked.

Lastly using Eclipse, write a program that teaches arithmetic to your younger brother. The program tests addition and subtraction. In level 1 it tests only addition of numbers less than 10 whose sum is less than 10. In level 2 it tests addition of arbitrary one-digit numbers. In level 3 it tests subtraction of one-digit numbers with a non-negative difference. Generate random problems and get the player input. The player gets up to two tries per problem. Advance from one level to the next when the player has achieved a score of five points.


Use the following class as your main class:
/**
This program runs the math game.
*/
public class MathGameRunner
{
public static void main(String[] args)
{
MathGame game = new MathGame();
game.play();
}
}

Thursday, April 24, 2008

Recursive

Write and test a recursive method/function that returns the maximum among the first n elements of an array.

More recursive fun:

Write and test a recursive method/function that returns the SUM of the squares of the first n positive integers.

Put your code on your blog when you are finished!

GCD

Examine this code for GCD:
public static int gcd(int m, int n)
{
if(m==n) return n;
else if(m < n) return gcd(m,n-m);
else return gcd(m-n,n);
}
//WHY DOES THIS WORK???

Think about them before you give up.

More brain teasers:

  1. Consider a two-player game played on a circular table of unspecified diameter. Each player has an infinite supply of quarters, and take turns placing a quarter on the table such that it is completely on the table and does not overlap with any other quarters already played. A player wins if he makes the last legal move. Which player (if any) has a strategy that will guarantee a win, and what is that strategy?
  2. How do you divide a cake among n people, maximizing fairness?

What do you think?

Blog post about Microsoft

http://moishelettvin.blogspot.com/2006/11/windows-shutdown-crapfest.html

When you are done checking out the article, I'd like you to attempt this test online:

http://www.betterprogrammer.com/

Better "Tower of Hanoi"

public class Hanoi {
public static void main(String [] args)
{
runHanoi(3,'A', 'B', 'C');
}

public static void runHanoi(int n, char x, char y, char z)
{
if(n==1)
System.out.println("Move top disk from peg " + x
+ " to peg " + z);
else
{
runHanoi(n-1,x,z,y);
runHanoi(1,x,y,z);
runHanoi(n-1,y,x,z);
}
}
}

Very strict OO approach

Check this out:

http://binstock.blogspot.com/2008/04/perfecting-oos-small-classes-and-short.html


  • Lots of methods!
  • Longer variable names!
  • No else?

Comment on your blog: what do you think about this approach?

GUI Programming

import javax.swing;
//New Frame
//New Label
//add
//setVisible(true)
//setSize

Here's some source code:
Calculator example.

Remember what we did with connecting Java to the database?

Look at this.

Tuesday, April 22, 2008

sum all the values of an array

/**
Computes the sum of a set of data values.
*/
public class DataSet
{
/**
Constructs a DataSet object.
@param values the data values
@param first the first value in the data set
@param last the last value in the data set
*/
public DataSet(int[] values, int first, int last)
{
this.values = values;
this.first = first;
this.last = last;
}

/**
Gets the sum in the set of data values
@return the sum value in the set
*/
public int getSum()
{
if (first > last)
return 0;
DataSet tail = new DataSet(values, first + 1, last);
int tailSum = tail.getSum();
return values[first] + tailSum;
}

private int[] values;
private int first;
private int last;
}

Your final project

I would like for you to think of an interesting problem to solve using Java. It could be console based or done with Netbeans or even an applet coded from scratch!

I'd like for you to think about something you are interested in! If you are into cars maybe you could think of a Java application that helps a dealer. If you like games, perhaps you can come up with an interesting game! Please write your idea on your blog today.

Final due:
MAY 3rd 2008 at 8am!!!!

Question and solution

Using recursion, find the largest element in an array.
public class DataSet
{
public DataSet(int[] values, int first, int last) { . . . }
public int getMaximum() { . . . }
. . .
}
Hint: Find the largest element in the subset containing all but the last element. Then compare that maximum to the value of the last element.


Used the following class as your tester class:
import java.util.Random;

/**
A tester class for the recursive maximum.
*/
public class DataSetTester
{
public static void main(String[] args)
{
int[] values = { 1, 10, 100, -1, -10, -100, 100, 0 };
DataSet d = new DataSet(values, 0, values.length - 1);
System.out.println("Maximum: " + d.getMaximum());
System.out.println("Expected: 100");
}
}


//SOLUTION:

/**
Computes the maximum of a set of data values.
*/
public class DataSet
{
/**
Constructs a DataSet object.
@param values the data values
@param first the first value in the data set
@param last the last value in the data set
*/
public DataSet(int[] values, int first, int last)
{
this.values = values;
this.first = first;
this.last = last;
}

/**
Gets the maximum in the set of data values
@return the maximum value in the set
*/
public int getMaximum()
{
if (first > last)
return Integer.MIN_VALUE;
DataSet tail = new DataSet(values, first + 1, last);
int tailMax = tail.getMaximum();
return Math.max(values[first], tailMax);
}

private int[] values;
private int first;
private int last;

Recursion explained graphically with Paint

http://weblogs.java.net/blog/mortazavi/archive/2005/08/recursive_progr.html

Tower of Hanoi!

Put on blog!

Chapter 13: Recursion!

Which way do you see her going?

Click here!

Monday, April 21, 2008

Random?

I found this graphic representation of Java's random function.

http://www.alife.co.uk/nonrandom/

It doesn't appear that random.

Also, this can't be true, can it?

Thursday, April 17, 2008

Interested in Linux?

Check this out.

Check this out!

Here is a great book for algorithm and data structure design:

http://books.google.com/books?q=The+Algorithm+Design+Manual+

Click on the first link. I doubt Google will update THEIR algorithm until you click on the link. ;)

Isn't books.google.com cool?

---

Also I would like for you to check out this tutorial about game design with Java.

After the test...

Today's "minor project" is to create a Jumble game where the user is given a scrambled word and they have to enter in the correct word. You can use Netbeans to create a GUI or use a console based application.

This is what I'm talkin' bout!!!

Show me it works when you are finished.

Read this article and respond to it on your blog.

Read this article and let me know what you think. Good idea?

Funny explanation for inner classes!

Read this to better understand inner classes:
http://www.javaranch.com/campfire/StoryInner.jsp

Tuesday, April 15, 2008

Next Project 6

davidcfreer.com/~David/zuul-better.zip

For the next major project you will have two choices...you can either create a console based Monopoly game (or graphical Monopoly game for major extra credit) or you can edit the code and create an interesting game out of the source code above.

Other creative game ideas are possible as well. Let me know.

DUE next Tuesday.

Monopoly Pseudocode

Start with students writing on their blogs the pseudocode for Monopoly.
Thinking in an object oriented fashion!

What classes would they need?

What methods would they need?

What instance variables?

http://en.wikipedia.org/wiki/Monopoly_(game)

Chapter 9

Polymorphism

What is polymorphism?

Great overview from Sun.

Not related to programming...

but really interesting nonetheless.

Monday, April 14, 2008

A little project I'm working on now...

One of my fav. games :)

public class Monopoly {
private Property [] gameboard = new Property[40];
//create new game board

public Monopoly()
{
gameboard[0] = new Property("Go");
gameboard[1] = new Property("Mediterranean");
gameboard[2] = new Property("Community Chest");
gameboard[3] = new Property("Baltic");
gameboard[4] = new Property("Income Tax");
gameboard[5] = new Property("Reading Railroad");
gameboard[6] = new Property("Oriental");
gameboard[7] = new Property("Chance");
gameboard[8] = new Property("Vermont");
gameboard[9] = new Property("Connecticut");
gameboard[10] = new Property("Jail");//all okay
gameboard[11] = new Property("St. Charles");
gameboard[12] = new Property("Electric");
gameboard[13] = new Property("States");
gameboard[14] = new Property("Virginia");
gameboard[15] = new Property("Pennslyvania Railroad");
gameboard[16] = new Property("St. James");
gameboard[17] = new Property("Community Chest");
gameboard[18] = new Property("Tennessee");
gameboard[19] = new Property("New York");
gameboard[20] = new Property("Free Parking");
gameboard[21] = new Property("Kentucky");
gameboard[22] = new Property("Chance");
gameboard[23] = new Property("Indiana");
gameboard[24] = new Property("Illinois");
gameboard[25] = new Property("B&O Railroad");
gameboard[26] = new Property("Atlantic");
gameboard[27] = new Property("Ventnor");
gameboard[28] = new Property("Waterworks");
gameboard[29] = new Property("Marvin Gardens");
gameboard[30] = new Property("Go to jail");
gameboard[31] = new Property("Pacific");
gameboard[32] = new Property("North Carolina");
gameboard[33] = new Property("Community Chest");
gameboard[34] = new Property("Pennslyvania");
gameboard[35] = new Property("Short Line Railroad");
gameboard[36] = new Property("Chance");
gameboard[37] = new Property("Park Place");
gameboard[38] = new Property("Luxury Tax");
gameboard[39] = new Property("Boardwalk");
//all full!
}
public int[] returnOwner()
{
int []i = new int[40];

}

Friday, April 11, 2008

Fifth Major Assignment

The Fifth Major Assignment is straight from the book and relates to inheritance.

Answer Exercises P10.3, P10.5, P10.6 by Monday at 11:59am. (Deadlines are good for focusing your attention.)

Please put each question in a separate folder on your FTP space.

Tuesday, April 8, 2008

ArrayList, LinkedList...intro to Data Structures

Here is the code for the ArrayList examples.

Read about dynamic arrays.

Here is the example for the LinkedList.

Read about linked lists.

Major Assignment Three and Four

Major Assignment 3:
As promised, here's your next major assignment which will be due before midnight on Sunday April 5th 2008. I'm in the process of going over the Blackjack programs tonight.

For this third assignment, I'm giving you a completed class and two partially completed classes for a mail server system.

Use BlueJ for this assignment. Create a new project called mail-system and within it three classes: MailClient, MailServer, MailItem.

Use the code I gave you but fill in the missing behaviors based on the names of the methods. It's quite a bit simpler than the Blackjack program.


Here's the code for the classes.
On blog for Record Keeping
Emailed April 2nd.


Major Assignment 4:
Create a Tic Tac Toe GUI by Sunday at midnight.
+20 points for an Applet online at davidcfreer.com

What are you interested in doing for a final project?

Any ideas?

For fun, try this out!

Check out the source code...pretty cool.

Also about video games, did you know what a "kill screen" is? Funny.

Evaluations Today:

YEAR: 72

IDENTIFICATION NUMBER: 200446993

If programming languages were boats...

Funny post.

Thursday, April 3, 2008

Tuesday, April 1, 2008

What is your feeling about BlueJ as a tool to learn Java?

Good, bad, or negative?

Predicting the future...

Will Java be used much in 10 years ? Why or why not? Try to predict the future...

Create new database, table, and front-end app with Netbeans

Using the steps we just did in class, make a database, table and front end application with Netbeans. It can be about anything you want! Show me and I'll grade it in class.

Creating tables within MySQL

CREATE TABLE address_books (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15), PRIMARY KEY (phone_number));


INSERT INTO address_books (first_name,last_name,phone_number) VALUES ('David','Freer','786-877-4573')";

Thursday, March 27, 2008

Alternating counter

http://docs.google.com/Doc?id=dc65q8nz_407c6kgxbdp

Please upload to your FTP space!

Programming problems for your perusal!

Project Euler.

LoveTester!

Today we are going to be using NetBeans 6.0!

In class we did the following examples:

  • Print out to the console from info entered in a text field.
  • Ask a user for a number and give the user that number doubled.
  • Ask a user for a number and multiply it by a second number entered by the user.

To accomplish the second and third task we needed to first save the data (accessed on the text field with the .getText() method) and then parse the data (think casting!) as an integer.


Here's the code we used in class:

public void doubleNumber() {

numToMultiply = jTextField1.getText();
numToMultiplyBy = jTextField2.getText();
//Getting the info from the text field
numberToMultiply = Integer.parseInt(numToMultiply);
numberToMultiplyBy = Integer.parseInt(numToMultiplyBy);
finalNumber = numberToMultiplyBy * numberToMultiply;
//Double the number
// numToDouble = Integer.toString(numberToDouble);
//Convert the doubled number to a String
newNum.setText(Integer.toString(finalNumber));
// Set the label "newNum" with the doubled number!
}
private String numToMultiply, numToMultiplyBy;
private int numberToMultiply, numberToMultiplyBy, finalNumber;

The in-class assignment was to create a LoveTester that asks the user for 3-5 pieces of information about himself and 3-5 pieces of information about his lover. The complicated LoveTester Algorithm (patent pending) is going to reveal the level of attraction, lust, and love for the two people!

Tuesday, March 25, 2008

After the test, we are going to start designing with NetBeans

After the test, I would like you to begin designing with Netbeans. Since your next major project is about games, I want you to check out the Anagram example from the Welcome screen. Click on General under Sample Projects and then click on "Anagram game".

Sunday, March 23, 2008

Is Java so easy you can learn it while you drive to work?? What's the signifcance here?

I think the picture's kinda funny.

After your test you can work on these tutorials

Graphics tutorials from Sun.

Blog assignment #5: How do you comment when you write programs?

Blog assignment #5:

First, read this. On your blog, answer the following question: how do you comment when you are programming? Do you add attributes and methods to a class and then add comments at the end? Do you write comments as you code? Lastly, what did you think of the article. Title this blog post- Blog assignment #5.


Blog assignment #4:
The following blogs are very useful to aspiring computer scientists:

You are going to read through them and write three blog posts in reaction to their posts on your own blog. Provide a link to the post that you found interesting!

You may want to add them to your Google Reader account.

Blog assignments #1-3:
If you haven't done the first three blog posts, here are the links:

Wednesday, March 19, 2008

Check this out...

Java is being replaced...

Here's another resource if you don't have the book yet.

Tuesday, March 18, 2008

Lunch Cart Example

/*
* Class LunchCart-
*
* Attributes:
* totalProfit
* numSandwiches
* numSodas
* totalTaxes
*
*
* Methods:
*
*
* Class Employees(String employee_num, String emp_name, int hours_wked)
* Class Employees(String employee_num, String emp_name)
* {
*
* }
* Attributes:
* hoursWorked
* employeeNumber
* salary
*
*
* Methods:
* getTotalHoursWorked()
* setTotalHoursWorked()
* getEmployeeNumber()
*
*/
public class LunchCart {
//Input, output using Scanner
//Process data using relevant conditionals and/or looping.
//What's most important for the LunchCart!!

}

Add the guessing game to Google Documents

Add me as a viewer (david.freer@gmail.com) just paste your code from Eclipse into Google Docs.

Here's your guessing game Guessing.java assignment

//Write a guessing game with Java where the user guesses a number between one and 100 and
// you give tips based on how close or far they are. If they are 20+ digits away you can lol
//or if they are within 10-20, say they are within a decent range, otherwise say they are getting
//closer!

Thursday, March 13, 2008

Post URL for Tic Tac Toe code!

Under the layout of your blog add the code for links.

In the links add the URL to the Tic Tac Toe source code that you found. Title it "Tic Tac Toe Source Code".

First In-"Class" Assignment

Email me at david.freer@gmail.com all the necessary .java code for your first OO example. Can be zipped or not, your choice. Consider the BlueJ practice!

Assignment 1

To input data using Scanner!!!

Click here for the document.

Tuesday, March 11, 2008

Car.java

/*
* Car.java
*
* Created on March 11, 2008, 8:20 PM
*
* To keep accurate account of our cars.
*/

/**
*
* @author dfreer
*/
public class Car {

boolean start = false;
String engine = "";
String brake = "";
private String name = "Herbie";
/** Creates a new instance of Car */
public Car(String eng, String br, String n) {
//constructor
engine = eng;
brake = br;
name = n;
}

public String getEngine()
{
return engine;
}

public void changeEngine(String ch)
{
engine = ch;
}
public boolean startEngine()
{
start = true;
return start;
}

public String getName(){
return name;
}
public static void main(String [] args)
{
Car herbie = new Car("3.8L", "moderate", "George");
System.out.println(herbie.getEngine());
herbie.changeEngine("V8");
System.out.println(herbie.getEngine()+ " is the engine of the new and improved " + herbie.getName());
}
}

Introductions

A bit about you and what you expect from the course.

Chapter 2 Notes

Chapter 1 Notes

Monday, March 10, 2008

Install at home

Here's a good place to start.

What is the SDK? Here's a good place to start.

Download eclipse, netbeans, and bluej.

Download JDK 6 Update 5

Find five sites with Sun Certified practice questions online

Here's a sample.

Third post:

Find five sites that have sample Sun Certified Java Programmer questions and write a review of each of the sites on your blog.

Tuesday, March 4, 2008

First post:

As concisely as possibly describe on your blog the purpose of the following site:
Java API.

Second post:
What is the purpose of the Java Virtual Machine?

Wednesday, February 20, 2008

Hacking Mozilla

You may find this fascinating.

"Everything is easy after you see it done."

Educators, generals, dieticians, psychologists, and parents program. Armies, students, and some societies are programmed. An assault on large problems employs a succession of programs, most of which spring into existence en route. These programs are rife with issues that appear to be particular to the problem at hand. To appreciate programming as an intellectual activity in its own right you must turn to computer programming; you must read and write computer programs -- many of them. It doesn't matter much what the programs are about or what applications they serve. What does matter is how well they perform and how smoothly they fit with other programs in the creation of still greater programs.


-http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-5.html

Sunday, January 20, 2008

Welcome!

In class we'll learn how to program using Java.

Consider this quote:

"Instead of imagining that our main task is to instruct a
computer what to do, let us concentrate rather on explaining to
human beings what we want a computer to do." - Donald Knuth

Think of computer programs as a work of literature. PEOPLE need to be able to understand your code. PEOPLE will update your code. Computers do as they are told. We will focus on communication as well as abstract thinking and algorithm design. Consider this: developers need a sense of aesthetics. Is the GUI completely chaotic? Are users cursing you?

If so, you'll need the communication skills to allay their discomfort and redesign the program.