Monday, June 29, 2009

Find 5 blogs about programming/IT

google.com/reader

Describe five of the blogs you picked on your blog.

How is your progress with BlackJack?

  1. What have you done so far?
  2. What classes do you have so far?
  3. What is hard and what is easy about the process?
  4. Have you ever programmed a game before?
  5. Check out kenai.com
  6. Check out Google Code: Monopoly.

Probability

What's the probability of rolling a 2 at least twice out of three rolls?

The die has 6 sides and you'll have to show me how you figured it out. (Extra point on your next test if you show me on Wednesday.)

Wednesday, June 24, 2009

Minor Project

//Computer Inventory
//Keep track of five things. Get the info from the user (console or gui).
//Write the data about the computer inventory to a file!

Monday, June 22, 2009

Please comment on this article on your blog

Read this article and comment on your own blog. Do you agree with the author's sentiments?

Major Assignment 3 due June 28, 2009

From 10.6

Create a GUI to add workers, hours and determine their salary.

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.

Also 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'');
}
}

Saturday, June 20, 2009

Solutions to second Project Euler

long* fib = new long[3];
fib[0] = 1;
fib[1] = 2;
long total = 0;
while(true) {
fib[2] = fib[0]+fib[1];
fib[0] = fib[1];
fib[1] = fib[2];
if(fib[2]>=1000000)
break;
if(fib[2]%2==0)
total+=fib[2];
}
System.out.println(total);

------

Another solution:

public class Problem2 {
public static void main(String[] args) {
int fib1 = 0;
int fib2 = 0;
int curFib = 1;
int sum = 0;
while(curFib < 1000000){
if(curFib % 2 == 0){
sum += curFib;
}
fib1 = fib2;
fib2 = curFib;
curFib = fib1 + fib2;
}
System.out.println("Solution to problem 2 = " + sum);
}
}

Wednesday, June 17, 2009

Room 2128

I'll be in room 2128 at 1pm this Saturday to review. See you there!

Monday, June 15, 2009

Real Estate GUI

With another person (or two, or by yourself), I would like you to create three classes for a Real Estate Business. The first will be a property class with an address, price, and area. The Residential class and Commercial class will be the subclasses of the Property class. Add two attributes to each subclass.
---
Create a GUI to enter the information about the Residential or Commercial properties. Store them in an ArrayList.

Have the ability to output the ArrayList to the console.

Sunday, June 14, 2009

Wednesday, June 10, 2009

Coding this weekend.

If anyone wants to review Java, I'll be available this Saturday at 1:00 pm in room 2128 at the Kendall Campus.

Hospital Project

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.

Monday, June 8, 2009

Fun assignment to end the day with !

Add all the natural numbers below one thousand that are multiples of 3 or 5.

Wednesday, June 3, 2009

Major Assignment 2

There is better formatting here.





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

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]");
}
}

On your blog...

Define the following terms:

  • Interface
  • Polymorphism
  • Inner class

What are they used for? Where did you find good information about the terms?

Tuesday, June 2, 2009