Adding More Translations

This commit is contained in:
Bradley Bickford 2022-12-10 21:26:01 -05:00
parent 543bc78e51
commit d96e315705
9 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,20 @@
class Ball():
def __init__(self, diameter, color):
self.diameter = diameter
self.color = color
self.timesBounced = 0
def getDiameter(self):
return self.diameter
def getColor(self):
return self.color
def getTimesBounced(self):
return self.timesBounced
def bounceBall(self):
self.timesBounced += 1
def __str__(self):
return "This ball is " + self.color + " with a diameter of " + str(self.diameter) + " and has been bounced " + str(self.timesBounced) + " times!"

View File

@ -0,0 +1,22 @@
Write a class called Ball with the following
- Characteristics
- diameter (float)
- color (string)
- timesBounced (int)
- Behaviors
- bounceBall
- getDiameter
- getColor
- getTimesBounced
Create 2 Balls
- Ball 1
- Diameter: .5
- Color: Red
- Bounce the ball 10 times
- Ball 2
- Diameter: 1
- Color: Yellow
- Bounce teh ball 1 time
Print all the values for both balls

View File

@ -0,0 +1,12 @@
import Ball
ball1 = Ball.Ball(5, "Red")
ball2 = Ball.Ball(1, "Yellow")
for i in range(10):
ball1.bounceBall()
ball2.bounceBall()
print(ball1)
print(ball2)

View File

View File

@ -0,0 +1,21 @@
class Tree():
def __init__(self, typeOfTree, height, width):
self.typeOfTree = typeOfTree
self.height = height
self.width = width
def getTypeOfTree(self):
return self.typeOfTree
def getHeight(self):
return self.height
def getWidth(self):
return self.width
def grow(self, heightAdd, widthAdd):
self.height += heightAdd
self.width += widthAdd
def __str__(self):
return "Type of Tree: " + self.typeOfTree + " Height: " + str(self.height) + " Width: " + str(self.width)

View File

@ -0,0 +1,10 @@
import Tree
oakTree = Tree.Tree("Oak", 10, .5)
pineTree = Tree.Tree("Pine", 25, 1.25)
print(oakTree)
oakTree.grow(5, .5)
print(oakTree)
print(pineTree)

View File