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!