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.