|
 |
|
 |
10-12-2006, 12:22 PM
|
#1 (permalink)
|
|
Recruit
Join Date: Oct 2006
Posts: 5
|
OOP logic??
Hello all... greenest newbie on earth here - looking for help.
I am taking a class called OOP Logic and Design. It's a prerequisite to all OOP Language classes unfortunately. I thought it would be so enlightening - and maybe it still will be - but at the moment, i'm thoroughly confused. :p
Writing blind pseudo-code that you can't test or execute makes it difficult to understand what you are doing. Also, the book is so .... thorough, i guess...that picking out the high-points - the things that'll help when it's time for homework - is near impossible. That being said, and being only a few chapters in, I have a simple assignment this week. Yet some of the logic is lost on me - since we're writing this pseudo-code in a vacuum.
Here is one of the exercises:
"Rick Hammer is a carpenter who wants an application to compute the price of any desk a customer orders, based on the following: desk length and width in inches, type of wood, and number of drawers. The price is computed as follows:
- The charge for all desks is a minimum of $200
- If the surface (length*width) is over 750 sq in, add $50
- If the wood is 'mahogany' add $150; oak add $125. No charge is added for pine.
- For every drawer in the desk, there is an additional $30 charge.
Design:
A. an 'Order' class including order number, customer name etc, and all the fields mentioned above. Include get and set methods for each field.
B. An application that accepts an 'Order' and displays all the relevant info and the price."
I should add that this follows a chapter on flowcharting. I believe they are looking for us to use what we learned - ie: utilize a case structure for one item like woodType, etc.
So far, I've declared my variables, wrote the set/get statements including (hopefully) decent calculations for the price variables.
The application part is hairier for me, and I'm not sure what I'm doing. Been digging through my book but i'm still kind of lost. (their examples are always just a couple of lines of pseudo-code for the particular topic, thus rendering it basically useless when you're trying to structure everything together  )
*sigh*
If anyone has an urge to help me get this down on paper and understand what I did, i'd be most grateful. I'm not willing to bypass understanding the basic class, method and structure information they're trying to impart because the book sucks. :p
Forever grateful,
Jacquie
|
|
|
10-12-2006, 12:34 PM
|
#2 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 677
|
how are you writing your application? C++, C#, .NET, .NET2, Delphi, Java, PHP 5, etc. ?
__________________

UT: Ultra-kill... God like!
|
|
|
10-12-2006, 01:28 PM
|
#3 (permalink)
|
|
Recruit
Join Date: Oct 2006
Posts: 5
|
Quote:
|
Originally Posted by DJMaze
how are you writing your application? C++, C#, .NET, .NET2, Delphi, Java, PHP 5, etc. ?
|
no language. strictly pseudo-code.
|
|
|
10-12-2006, 04:57 PM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,489
|
here is some quick code i wrote that meets the criteria i think.. you could probably use it as a base line for your psuedo code
hey djm, isn't there a slick get/set model for PHP 5 classes?
PHP Code:
<? class Order { public $orderNumber; public $customerName; public $length; public $width; public $woodType; public $drawerCount; public $totalCost;
public function setOrderNumber($orderNumber) { $this->orderNumber = $orderNumber; }
public function getOrderNumber() { return $this->orderNumber; }
public function setCustomerName($customerName) { $this->customerName = $customerName; }
public function getCustomerName() { return $this->customerName; } public function setLength($length) { $this->length = $length; }
public function getLength() { return $this->length; } public function setWidth($width) { $this->width = $width; }
public function getWidth() { return $this->width; } public function setWoodType($woodType) { $this->woodType = $woodType; }
public function getWoodType() { return $this->woodType; } public function setDrawerCount($drawerCount) { $this->drawerCount = $drawerCount; }
public function getDrawerCount() { return $this->drawerCount; } public function setTotalCost($totalCost) { $this->totalCost = $totalCost; } public function getTotalCost() { return $this->totalCost; } public function calculateTotalCost() { $cost = 200; // check surface for cost if (($this->getWidth() * $this->getHeight()) > 750) { // add fifty bucks $cost += 50; } // check wood for cost switch ($this->getWoodType()) { case "mahogany": $cost += 150; break; case "oak": $cost += 125; } // check drawer count for cost $cost += $this->getDawerCount()*30; // set total cost setTotalCost($cost); } }
// example use $order = new Order();
$order->setOrderNumber(12345); $order->setCustomerName("John Smith"); $order->setLength(24); $order->setWidth(48) $order->setWoodType("oak"); $order->setDrawerCount(4);
$order->calculateTotalCost(); ?>
__________________
Mike
|
|
|
10-12-2006, 08:14 PM
|
#5 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
|
I thought there was a rule somewhere that all object oriented psuedo code has to be either in smalltalk or object pascal. 
__________________
Stop intellectual property from infringing on me
|
|
|
10-13-2006, 05:39 AM
|
#6 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
|
Quote:
|
I thought there was a rule somewhere that all object oriented psuedo code has to be either in smalltalk or object pascal.
|
Hmm.. I always thought Emerald was a decent way to write pseudo OO code in.
|
|
|
10-13-2006, 06:24 AM
|
#7 (permalink)
|
|
Recruit
Join Date: Oct 2006
Posts: 5
|
SDE, Thank you for doing that...it was very helpful! I owe you!
Here is what I have so far - remember, this is just generic pseudocode that I need to turn in with no shortcuts/abbreviations etc. One thing I'm confused about. In the application class, when I get the different variables, do I need to initialize those? I did for OrderNumber as I can enter a starting value but the others i am not sure about.....
Please let me know if you see any problems with structure, how i've calculated the totalCost or with the use of public/private (should the calculations be private?) or void/static. These are the details I don't have confidence in yet... You guys are more helpful than my book or instructor.
Code:
Class Order
private numeric orderNumber
private string custLName
private string custFName
private string custStrAddr
private string custCity
Private string custState
private string custZip
private string custTelNo
private numeric length
private numeric width
private string woodType
private numeric drawerCount
private numeric totalCost
public numeric getOrderNumber()
return orderNumber
public void setOrderNumber(numeric num)
orderNumber = num
return
public string getCustLName()
return custLName
public void setCustLName(string lastName)
custLName = lastName
return
public string getCustFName()
return custFName
public void setCustFName(string firstName)
custFName = firstName
return
public string getCustStrAddr()
return CustStrAddr
public void setCustStrAddr(string address)
CustStrAddr = address
return
public string getCustCity()
return CustCity
public void setCustCity(string city)
custCity = city
return
public string getCustState()
return CustState
public void setCustState(string state)
custState = state
return
public string getCustZip()
return custZip
public void setCustZip(string zipCode)
custZip = zipCode
return
public string getCustTelNo()
return CustTelNo
public void setCustTelNo(string telNo)
custTelNo = telNo
return
public numeric getDeskLength()
return deskLength
public void setDeskLength(numeric num)
deskLength = length
return
public numeric getDeskWidth()
return deskWidth
public void setDeskWidth(numeric num)
deskWidth = width
return
public string getWoodType()
return woodType
public void setWoodType(string wood)
woodType = wood
return
public numeric getDrawerCount()
return drawerCount
public void setDrawerCount(numeric drawers)
DrawerCount = drawers
return
public numeric getTotalCost()
return totalCost
public void calculateTotalCost()
numeric totalCost = 200
case based on woodType
case "Pine"
totalCost = 200
case "Oak"
totalCost = 325
case "mahogany"
totalCost = 350
default
totalCost = 200
print "Error - Enter valid wood type"
endcase
if deskLength * deskWidth > 750 then
totalCost = totalCost + 50
default
totalCost = totalCost
print "Error - Enter dimensions of desk"
endif
if drawerCount > 0 then
totalCost = totalCost + (drawerCount * 30)
default
totalCost = totalCost
print "Error - Enter number of desk drawers"
endif
return
endClass
class NewDesk
public static void main()
Order desk
desk.setOrderNumber(123)
desk.setCustFName()
desk.setCustLName()
desk.setCustStrAddr()
desk.setCustCity()
desk.setCustState()
desk.setCustZip()
desk.setCustTelNo()
desk.setTotalCost()
print "Order Number:", desk.getOrderNumber(123)
print "Price:", desk.getPrice()
print "First Name:", desk.getCustFName()
print "Last Name:", desk.getCustLName()
print "Address:", desk.getCustStrAddr()
print "City:", desk.getCustCity()
print "State:", desk.getCustState()
print "Zip Code:", desk.getCustZip()
print "Phone Number:", desk.getCustTelNo()
print "Custom Details:"
print "Desk Dimensions:", desk.getLength(), "by" desk.getWidth()
Print "Wood Type:", desk.getWoodType()
print "Number of Drawers:", desk.getDrawerCount()
print "Total Cost", desk.getTotalCost()
print "Rick thanks you for your business!"
return
endClass
|
|
|
10-13-2006, 10:43 AM
|
#8 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,489
|
yeah, you should probably initialize the variables in a constructor function. i'm not sure what it would look like in your psuedo code but a lot of languages use a function that has the same name as the class.
i.e: public void Order(){}
There you can initialize your variables to the type of var you defined.
customerName = "";
orderNumber = 0;
looks like you are using void appropriately.
__________________
Mike
|
|
|
10-13-2006, 10:53 AM
|
#9 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 677
|
Quote:
|
Originally Posted by sde
hey djm, isn't there a slick get/set model for PHP 5 classes?
|
Correct
PHP Code:
<?php
class aphp5class
{
# overloaders don't use the private, protected and public member definition
function __get($key)
{
if (isset($this->$key))
{
return $this->$key;
}
else
{
throw new Exception($key.' does not exist');
}
}
function __set($key, $value)
{
if (isset($this->$key))
{
$this->$key = $value;
mysql_query('UPDATE table SET '.$key.'=\''.$value.'\'');
}
else
{
throw new Exception($key.' does not exist');
}
}
}
__________________

UT: Ultra-kill... God like!
|
|
|
10-13-2006, 10:54 AM
|
#10 (permalink)
|
|
Recruit
Join Date: Oct 2006
Posts: 5
|
Quote:
|
Originally Posted by sde
yeah, you should probably initialize the variables in a constructor function. i'm not sure what it would look like in your psuedo code but a lot of languages use a function that has the same name as the class.
i.e: public void Order(){}
There you can initialize your variables to the type of var you defined.
customerName = "";
orderNumber = 0;
looks like you are using void appropriately.
|
thanks sde, i did work on initializing them - i think i did it right.
On top of this fun, my instructor is a British dude who writes things like "you can't do that!!!" and "where's your end statement???"
I can't bear his indignation again! :p
|
|
|
10-13-2006, 06:36 PM
|
#11 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
|
From a semantic standpoint, it seems hard to argue about syntax errors in psuedo code given the wide range of grammars for real programming languages. I mean what if my psuedo grammar makes all end tags implicit via indentation (like python)?
__________________
Stop intellectual property from infringing on me
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 09:33 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|