Archive for the 'Programming' Category

Cash Register

Another very tough week on the programming front. With the assistance of the ever patient and helpful graduate assistant, P$(@$(&k, I managed to cobble together some workable code. Below is the driver for the assignment (Coin and CashRegister classes used, not displayed here…why further embarass myself?):

public class CashRegisterDriver
public static void main(String[] args)
//Create coin set by integer value and type name
Coin penny = new Coin(1, “penny”);
Coin nickel = new Coin(5, “nickel”);
Coin dime = new Coin(10, “dime”);
Coin quarter = new Coin(25, “quarter”);

Scanner in = new Scanner(;

CashRegister register = new CashRegister();

//Input a purchase price amount for class CashRegister
//Input via Scanner
System.out.print(“Enter price: “);
int price = in.nextInt();

//Input payment amount for class CashRegister
//Create variable names for each coin type for payment method
System.out.print(“Please enter your payment as requested: \n”);
System.out.print(“Enter # of quarters: “);
int quarters = in.nextInt();
register.enterPayment(quarters, quarter);
System.out.print(“Enter # of dimes: “);
int dimes = in.nextInt();
register.enterPayment(dimes, dime);
System.out.print(“Enter # of nickels: “);
int nickels = in.nextInt();
register.enterPayment(nickels, nickel);
System.out.print(“Enter # of pennies: “);
int pennies = in.nextInt();
register.enterPayment(pennies, penny);

//Alert user to transaction values
System.out.print(“The price is: ” + register.purchase + “\n”);
System.out.print(“You have paid a total of: ” + register.payment + “\n”);
System.out.print(“Your change due is: ” + (register.payment – register.purchase) + “\n”);

//Create variable name for change method for each coin type created above
int q = register.giveChange(quarter);
System.out.print(“Quarters returned: ” + q + “\n”);
int d = register.giveChange(dime);
System.out.print(“Dimes returned: ” + d + “\n”);
int n = register.giveChange(nickel);
System.out.print(“Nickels returned: ” + n + “\n”);
int p = register.giveChange(penny);
System.out.print(“Pennies returned: ” + p + “\n”);


Any programmer that reads this will note that all monies and transactions are integer type…..I can’t figure out how to express an integer value in double format, nor can I figure out how to cast a double to an integer. If you are in my class, please don’t get us both in trouble by copying/using this doggerel.


Mobile post sent by Agricola using Utterz Replies.  mp3

Keyboard Shortcuts

For the record, I’ve been using a pc since 1984. The first machine was an IBM PC-XT. Self taught in Lotus 1-2-3, and then in Excel. Used to be completely functional in WordPerfect, until Word conquered the world. I’m no application wiz, but I can get basic stuff done. I’m a professionally trained typist, once capable of 60 WPM with a very high accuracy rate (today, the rate is much lower, but I’m still pretty good).

Last semester, I watched my computer science professor teach on a overhead connected to his laptop. He had the Python interpreter running, had the class website up, and the class wiki. Man, he was flying through the screens like Paul Revere through Boston. Highlighting, cutting, pasting, copying…….each class was a masterful performance of keyboard shortcuts. I, of course, had no clue how he was doing it.

One day, in our lab class, he came over to my partner and me to check our progress on a program. The method we used in the lab setting was that one of us was the ‘driver’, i.e., the keyboard operator, and the other was the ‘navigator’, i.e., the creator of the code. I happened to be driving that day, and thus had to repair some code to suit the professor’s taste. My ham-handed attempt at manipulation evoked a comment from the prof like this: “Why aren’t you using shortcuts?”…..”I don’t know how…..”….(to the other student) “How could you let him drive without knowing the shortcuts…..get on the keyboard!”

My humiliation was utter and complete. I imagined that I was the only buffoon in the entire class lacking such basic knowledge…..a leftover from the DOS universe, a remnant from a long dead culture. Such was my low estate that I never dared ask anyone else how to use the keyboard shortcuts.

Yesterday, while perusing the web-site for my new programming class, I stumbled upon a link to something call Productivity Hints. There they were! The techniques that I assumed were hidden to old Neanderthals such as myself…….

Ctrl + Tab………..Alt + Tab…..Shift arrows…….Ctrl + x…….Ctrl + C……Ctrl + v……

I have been practicing all day. I get them. I love it!

Datasets and Organization

New for this semester is a course on databases. Of all the work I have done so far, however hard/frustrating/educational it has been, it is worth the price of admission to this class. This is the first ‘hands-on’ class I will take that might establish a skill that will generate income dollars in the future. This is big-boy stuff, even though we are toddlers compared to the professionals.

Tonight I will download and install Microsoft’s SQL Server 2005. If it works, and it didn’t the first time, I will create my very first (and small) database.



First Program of the Semester

So the professor asks us to write a program in Python, after which she will show us the same program written in Java. The program was easy to develop conceptually, and the programming was, for the most part, easy. There were a few looks back into our Python Quick Reference, but not bad after a 4 week layoff. We’ll see what she thinks about the algorithm and the design. I expect the Java version to be way more complex, from a syntax point of view.

Here’s my code…..feel free to comment; it’s already been submitted so your thoughts will not incur an Honor violation.


import math

def ordQty(): # Get order quantity

n = input(“How many bags of coffee do you want to order? “)

while n <= 0: # Makes sure order is larger than 0

print”Invalid quantity. Your order must be at least 1 bag.”

n = input(“how many bags of coffee do you want to order? “)

return n

def discountTable(n, cost): # creates discount based on volume (per assignment parameters)

if n < 25:
discount = cost * 0.0

if n >= 25 and n < 50:
discount = cost * .05

if n >= 50 and n< 100:
discount = cost * .10

if n >= 100 and n< 200:
discount = cost * .15

if n >= 200 and n < 250:
discount = cost * .20

if n >= 250 and n < 300:
discount = cost * .25

if n >= 300:
discount = cost * .30

return discount

def boxTable(n): # calculates number of boxes required for order

A = n / 20 # A is the variable for large boxes. Returns an integer value

remA = n % 20 # remA calculates the remainder value for the A box divisor

B = remA / 10 # B is the variable for the medium boxes. Returns an integer value

remB = remA % 10 # remB calculates the remainder value for the B box divisor

C = remB / 5.0 # C is the variable for the small boxes. Returns a float value

Last = math.ceil(C) # Use ‘ceil’ function to determine next highest integer

costA = A * 2.0 # costA is the box charge for large boxes

costB = B * 1.0 # costB is the box charge for medium boxes

costLast = Last * .50 # costLast is the box charge for small boxes

boxCharge = (costA + costB + costLast) # Calculate total box cost for return

return boxCharge

def main():

n = ordQty()

cost = n * 5.50 # calculate cost of coffee before any discount

print “You have ordered”,n,”bags of coffee. The price is $%0.2f” % (cost)

discount = discountTable(n, cost) # create discount function, return discount amount

print “Your quantity discount is $%0.2f” % (discount)

boxCharge = boxTable(n) # calculate number of boxes required and cost

print”The box charge is $%0.2f” % (boxCharge)

totalCost = cost – discount + boxCharge # calculate order total

print “The total cost of your order is $%0.2f” % (totalCost)



The output of a test run:


How many bags of coffee do you want to order? 999
You have ordered 999 bags of coffee. The price is $5494.50
Your quantity discount is $1648.35
The box charge is $100.00
The total cost of your order is $3946.15


We Love Python


“Life’s hard, son. It’s harder when you’re stupid.” — The Duke.

Education is a companion which no misfortune can depress, no crime can destroy, no enemy can alienate,no despotism can enslave. At home, a friend, abroad, an introduction, in solitude a solace and in society an ornament.It chastens vice, it guides virtue, it gives at once grace and government to genius. Without it, what is man? A splendid slave, a reasoning savage. - Joseph Addison
The term informavore (also spelled informivore) characterizes an organism that consumes information. It is meant to be a description of human behavior in modern information society, in comparison to omnivore, as a description of humans consuming food. George A. Miller [1] coined the term in 1983 as an analogy to how organisms survive by consuming negative entropy (as suggested by Erwin Schrödinger [2]). Miller states, "Just as the body survives by ingesting negative entropy, so the mind survives by ingesting information. In a very general sense, all higher organisms are informavores." - Wikipedia

Blog Stats

  • 30,777 hits