No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md

README.md

General Assembly Logo

Modeling the Real World: Orange Tree Lab

Prerequisites

  • Know and use the basics of Python
  • Use Python Classes and Inheritance

Initial Setup

First, let's set up a python script:

$ mkdir orange-tree
$ cd orange-tree
$ touch orange_tree.py

1. Create an Orange class

  • Your orange class should initialize instances with diameter_in_cm and ripeness attributes
  • ripeness is measured on a scale of 1-5
  • It should have a method "ripen" that increases the ripeness by 1

2. Create an Orange Tree class

  • Your orange tree class should initialize with an empty array of "oranges"
  • It should take a "type" of orange that it grows.
  • It should print it's type and number of oranges
  • It should have a grow_oranges function that adds a few new instances of the Orange class to the array

Sample input:

myTree = OrangeTree("Navel")
myTree.grow_oranges()
print(myTree.oranges)

Sample output:

You created a Navel tree with 19 oranges
[<__main__.Orange object at 0x10b7412e8>, <__main__.Orange object at 0x10b741358>, <__main__.Orange object at 0x10b743f98>, <__main__.Orange object at 0x10b743fd0>, <__main__.Orange object at 0x10b75c978>, <__main__.Orange object at 0x10b75c748>, <__main__.Orange object at 0x10b75c128>, <__main__.Orange object at 0x10b75c588>, <__main__.Orange object at 0x10b75c860>, <__main__.Orange object at 0x10b75c7f0>, <__main__.Orange object at 0x10b75c898>, <__main__.Orange object at 0x10b75c908>, <__main__.Orange object at 0x10b75c780>, <__main__.Orange object at 0x10b75c7b8>, <__main__.Orange object at 0x10b760240>, <__main__.Orange object at 0x10b7605f8>, <__main__.Orange object at 0x10b760630>, <__main__.Orange object at 0x10b760668>, <__main__.Orange object at 0x10b7606a0>, <__main__.Orange object at 0x10b7606d8>, <__main__.Orange object at 0x10b760710>, <__main__.Orange object at 0x10b760748>, <__main__.Orange object at 0x10b760780>, <__main__.Orange object at 0x10b7607b8>, <__main__.Orange object at 0x10b7607f0>, <__main__.Orange object at 0x10b760828>, <__main__.Orange object at 0x10b760860>, <__main__.Orange object at 0x10b760898>, <__main__.Orange object at 0x10b7608d0>, <__main__.Orange object at 0x10b760908>, <__main__.Orange object at 0x10b760940>, <__main__.Orange object at 0x10b760978>, <__main__.Orange object at 0x10b7609b0>, <__main__.Orange object at 0x10b7609e8>, <__main__.Orange object at 0x10b760a20>, <__main__.Orange object at 0x10b760a58>, <__main__.Orange object at 0x10b760a90>, <__main__.Orange object at 0x10b760ac8>]

3. Add a two child-classes for Orange, Valencia, and Navel

  • Valencia Orange should have additional juice function
  • Navel Orange should have additional remove_lint function
  • Change the OrangeTree#grow_oranges function to grow the correct oranges for the tree's type

Sample input:

myTree = OrangeTree("Valencia")
myTree.grow_oranges()
print(myTree.oranges[0].juice())
print(type(myTree.oranges[0]))

myTree = OrangeTree("Navel")
myTree.grow_oranges()
print(myTree.oranges[0].remove_lint())
print(type(myTree.oranges[0]))

Sample output:

You created a valencia tree with 19 oranges
JUICY!
<class '__main__.ValenciaOrange'>
You created a navel tree with 19 oranges
gross.
<class '__main__.NavelOrange'>
  1. Bonus: Add an Orchard Class
  • Your orchard class should be initialized with an empty array of trees
  • This trees array should then be populated by an equal ammount of Valencia and Navel oranges.

Sample input:

myOrchard = Orchard()

Sample output:

You created a valencia tree with 19 oranges
You created a navel tree with 19 oranges
You created a valencia tree with 19 oranges
You created a navel tree with 19 oranges
You created a valencia tree with 19 oranges
You created a navel tree with 19 oranges
You created a valencia tree with 19 oranges
You created a navel tree with 19 oranges
You created a valencia tree with 19 oranges
You created a navel tree with 19 oranges
You created a valencia tree with 19 oranges
You created a navel tree with 19 oranges
You created a valencia tree with 19 oranges
You created a navel tree with 19 oranges
You created a valencia tree with 19 oranges
You created a navel tree with 19 oranges
You created a valencia tree with 19 oranges
You created a navel tree with 19 oranges
You created a valencia tree with 19 oranges
  1. Bonus Part II: Get creative! Add whatever else you might want.
  • One suggestion: a basket class that can hold picked oranges.

Resources:

Solution Code