[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] [dynamic_omaha] Requirements Part 4 for August 7: Groovy Coding: Car Wash



Here's a Perl mock-up I wrote after the meeting. The original challenge is below.

It's kinda fun to hold down the insert money key and watch your balance fly up and then hold down a purchase key and spend your loot. :)

j

------------------------------
#!/usr/bin/perl

use strict;
use Term::InKey;
use FileHandle;
STDOUT->autoflush();

# Slap your products in here (up to 9 of them)...
my $tmp = <<EOT;
Simple       5    Wash
Clean        6    Wash,Soak
Stupendous   7    Wash,Soak,Wax
EOT

# Thanks, simple human. Now Perl will do the dirty work,
# building the structures we'll need to get the job done.
my ($products, @products, $product_choices);
foreach my $line (split /\n/, $tmp) {
   my ($product, $cost, $actions) = split / +/, $line;
   push @products, $product;
   my $cnt = @products;
   $products->[ $cnt ] = {
      cost    => $cost,
      actions => $actions
   };
   $product_choices .= "  [$cnt] Buy $product (\$$cost)\n";
}

my $balance = 0;
my $message;
while (1) {
   &Clear;
   choices();
   print "> ";
   for (my $x = &ReadKey) {
      /i/  && do { dollar_inserted() };
      /q/  && do { exit };
      /\d/ && do { purchase($x) };
      next;
   }
}

# END MAIN

sub dollar_inserted {
   $balance++;
   $message = "Cha-ching!";
}

sub purchase {
   my ($product) = @_;
   my $amount = $products->[$product]->{cost};
   my $actions = $products->[$product]->{actions};
   return unless $amount;
   if ($balance < $amount) {
      $message = "Please insert more money first.";
      return;
   }
   $balance -= $amount;
   $message = "You just bought $actions for $amount dollars.";
}

sub choices {
   print <<EOT;

$message

Your balance: $balance

  [i] Insert dollar

$product_choices
  [q] Quit

EOT
   undef $message;
}
------------------------------



 -------Original Message-------
 From: Blaine Buxton <altodorado@blainebuxton.com>
 Subject: August 7: Groovy Coding: Car Wash
 Sent: 12 Jul '07 00:50

 Hello,
I thought I would do things a little differently next month and have a small design group session. I came up with some "customer requirements" that will be released in four rounds. I want this to inspire discussion so if you come up with a novel or clever solution. Please share it! Anything language is welcome to join in on the fun, so if Groovy is not your bag, please do it in the language of your choice. I would like for us to compare the different ways of doing and compare out thought processes. I think this will be more fun if everyone gets involved.

I made the first round simple (and in fact all of them are simple). I just wanted something easy enough to code, but interesting. The rounds following the first will be customer changes/additions to our requirements. If you get yourself in a corner because of changes, I would love to know what they were and how you overcame them. I think this will be an extraordinary learning experience and I hope it is successful!

 Customer Requirements:
Frobozz Gas and Go has installed a brand new automated car wash. There's just one problem. The hardware that runs the car wash has no software to run it. Basically, it's a coin-operated box that takes the customer's money and sends commands to the machine that washes the car. Frobozz has called us to design this software and this is the list of requirements:
 1. Machine Takes Cash/Gives Change
 2. There are 3 packages for the wash and their prices are:
         Simple $5.00 (Action Sent To Wash Machine: Wash)
         Clean $6.00 (Actions Sent To Wash Machine: Wash, Soak)
         Stupendous $7.00 (Wash, Soak, Wax)
 And that's it.
 The interface for the washing machine is this (Specified in Java):
 public interface CarWashMachine {
 public void performWash();
 public void performSoak();
 public void performWax();
 }

You are free to implement any interface you want for the machine that gives/takes money. You are also free to connect the CarWashMachine to anything you want. As long as the customer pays and gets the wash. Frobozz doesn't care.

These requirements are quite ambigious and Frobozz is a busy man. Good luck everyone!

I have a meeting with Frobozz next week to discuss anything that might have been missed.
 --
 Blaine Buxton
 Simplicity Synthesist
 http://blog.blainebuxton.com