Tuesday, February 24, 2009

The Next Netbeans ... 6.7

June 2009

Monday, February 23, 2009

Create a GUI that takes in input and gives it back in a text area

Think of a creative use for a GUI. Have the user give some information in, save it in some variables, and output it back to the user in a text area.

Zip it up and put it on your FTP space.

Funny

http://rymden.nu/exceptions.html

Friday, February 20, 2009

Wednesday, February 18, 2009

Major Assignment 3 Due

Exercise P10.5
Make a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an instance field, named department, of type String. Supply a method toString that prints the manager's name, department, and salary. Make a class Executive inherit from Manager. Supply appropriate toString methods for all classes. Supply a test program that tests these classes and methods.

Use the following class as your tester class:
/**
This program tests the Employee class and its subclasses.
*/
public class EmployeeTester
{
public static void main(String[] args)
{
Employee e = new Employee(''Edgar'', 65000);
Manager m = new Manager(''Mary'', 85000, ''Engineering'');
Executive v = new Executive(''Veronica'', 105000, ''Engineering'');
System.out.println(e);
System.out.println(''Expected: Employee[name=Edgar,salary=65000.0]'');
System.out.println(m);
System.out.println(''Expected: Manager[super=Employee[
name=Mary,salary=85000.0],department=Engineering]'');
System.out.println(v);
System.out.println(''Expected: Executive[super=Manager[
super=Employee[name=Veronica,salary=105000.0],
department=Engineering]]'');
}
}

Exercise P10.6
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'');
}
}
Due February 27, 2009

Monday, February 16, 2009

Read this article...

Blog Assignment:
Read this article.
  1. On your article, explain what the article is about in less than a paragraph.
  2. Do you agree with the author?

Thursday, February 12, 2009

Test 2 Review online

Look to the right. See you Monday. Study Chapter 7, 9, and 10.

DF

Wednesday, February 11, 2009

Today in class...

You will be doing a "minor project" with another classmate.

We will write software using Java for a hospital to track its patients. You will first make a Patient class and four necessary methods for the Patient. Create two possible constructors for your Patient class.

Use the Patient class to create a CriticalCare patient (Remember: extends). Add an extra method that a CriticalCare patient may need to have. Create a constructor for the CriticalCare patient.

Lastly create a Hospital class that has an ArrayList of Patients and CriticalCare patients.

Use a loop to ask a user to input the information to admit a Patient and a CriticalCare patient.

Please upload it to your FTP space as Hospital.zip.

DF

Monday, February 9, 2009

Define: Protected, super, and extends

On your blog define protected, super and extends.

Presentations

Chapter 9



Chapter 10

Friday, February 6, 2009

Second Major Assignment due February 16th







The following two programs comes from Chapter 7 in your textbook. Due Monday February 16th, 2009. Please upload both as one project and make sure to zip it before using FTP.

P7.2
Implement a class Purse. A purse contains a collection of coins. For simplicity, we will only store the coin names in an ArrayList. (We will discuss a better representation in Chapter 8.) Supply a method
void addCoin(String coinName)
Add a method toString to the Purse class that prints the coins in the purse in the format
Purse[Quarter,Dime,Nickel,Dime]
Use the following class in your solution:
import java.util.ArrayList;

/**
A purse holds a collection of coins.
*/
public class Purse
{
/**
Constructs an empty purse.
*/
public Purse()
{
coins = new ArrayList();
}

/**
Adds a coin to the purse.
@param coinName the coin to add
*/
public void addCoin(String coinName)
{
. . .
}

/**
Returns a string describing the object.
@return a string in the format "Purse[coinName1,coinName2,...]"
*/
public String toString()
{
. . .
}

private ArrayList coins;
}

Use the following class as your tester class:
/**
This class tests the Purse class.
*/
public class PurseTester
{
public static void main(String[] args)
{
Purse p = new Purse();
p.addCoin("Quarter");
p.addCoin("Dime");
p.addCoin("Nickel");
p.addCoin("Dime");

System.out.println(p.toString());
System.out.println("Expected: Purse[Quarter,Dime,Nickel,Dime]");
}
}

P7.3


Write a method reverse that reverses the sequence of coins in a purse. Use the toString method of the preceding assignment to test your code. For example, if reverse is called with a purse
Purse[Quarter,Dime,Nickel,Dime]
then the purse is changed to
Purse[Dime,Nickel,Dime,Quarter]
Use the following class in your solution:
import java.util.ArrayList;

/**
A purse holds a collection of coins.
*/
public class Purse
{
/**
Constructs an empty purse.
*/
public Purse()
{
coins = new ArrayList();
}

/**
Adds a coin to the purse.
@param coinName the coin to add
*/
public void addCoin(String coinName)
{
. . .
}

/**
Returns a string describing the object.
@return a string in the format "Purse[coinName1,coinName2,...]"
*/
public String toString()
{
. . .
}

/**
Reverses the elements in the purse.
*/
public void reverse()
{
. . .
}

private ArrayList coins;
}

Use the following class as your tester class:
/**
This class tests the Purse class.
*/
public class PurseTester
{
public static void main(String[] args)
{
Purse p = new Purse();
p.addCoin("Quarter");
p.addCoin("Dime");
p.addCoin("Nickel");
p.addCoin("Dime");
System.out.println("Original purse: " + p.toString());
System.out.println("Expected: Purse[Quarter,Dime,Nickel,Dime]");
p.reverse();
System.out.println("Reversed purse: " + p.toString());
System.out.println("Expected: Purse[Dime,Nickel,Dime,Quarter]");
}
}

Wednesday, February 4, 2009

Definitions

On your blog define and provide code examples (syntax) for the following terms:

  • Overloading
  • Interface
  • Polymorphism