Skip to content

Commit

Permalink
Добавлены новые методы.
Browse files Browse the repository at this point in the history
Добавил новые методы по взаимодействию со сборкой автомобиля, пояснил почему используется название Пассажир в дочернем классе, поменял строки имя, фамилия на название машины и класс машины, убрал из Родительского класса методы can_transport что бы в дочерних классах они считались переопределенными.
  • Loading branch information
Rammz022 authored Jan 11, 2021
1 parent 56dc9a3 commit 7337f11
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 50 deletions.
26 changes: 17 additions & 9 deletions Classes/main.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
from mashine.car import Car
from mashine.Cargo import Cargo
from mashine.Passenger import Passenger
from mashine.Passenger import Passengers

noname = Car("From Factory")
print(noname.last_name + " " + noname.first_name)
print(noname.class_name + " " + noname.car_name)
noname.drive()
noname.can_transport_cargo()
noname.can_transport_pessenger()

lada = Passenger("lada")
print(lada.first_name + " " + lada.last_name)
lada = Passengers("lada")
print(lada.car_name + " " + lada.class_name)
lada.drive()
lada.can_transport_cargo()
lada.can_transport_passenger()
lada.can_transport_passengers()
print(lada.body)
print(lada.engine)
print(lada.shassis)
print(lada.transmission)
lada.change_assembly("Gas", "back_wheel", "auto")
print(lada.engine)
print(lada.shassis)
print(lada.transmission)
lada.change_transporting_type("Cargo")
print(lada.body)
lada.color("red")
print(lada.weight_over_3_tons)
lada.change_weight(True)
print(lada.weight_over_3_tons)
lada.can_transport_cargo()
lada.can_transport_passengers()

kamaz = Cargo("Kamaz")
print(kamaz.first_name + " " + kamaz.last_name)
print(kamaz.car_name + " " + kamaz.class_name)
kamaz.drive()
kamaz.can_transport_cargo()
kamaz.can_transport_passenger()
kamaz.can_transport_passengers()
print(kamaz.body)
print(kamaz.engine)
print(kamaz.shassis)
Expand Down
21 changes: 17 additions & 4 deletions Classes/mashine/Cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@


class Cargo(Car):
def __init__(self, first_name, last_name="Cargo Car", body="cargo", engine="diesel", shassis="four_wheel",
"""Класс Грузовая(Машина)"""
def __init__(self, car_name, class_name="Cargo Car", body="cargo", engine="diesel", shassis="four_wheel",
transmission="auto", weight_over_3_tons=True):
self.first_name = first_name
self.last_name = last_name
super().__init__(car_name, class_name)
self.car_name = car_name
self.class_name = class_name
self.body = body
self.engine = engine
self.shassis = shassis
Expand All @@ -33,12 +35,23 @@ def can_transport_cargo(self):
else:
print("The car can`t transporting cargo.")

def can_transport_passenger(self):
def can_transport_passengers(self):
if self.weight_over_3_tons:
print("The car can`t transporting pessengers.")
else:
print("The car can transporting pessengers.")

def change_assembly(self, engine, shassis, transmission):
self.engine = engine
self.shassis = shassis
self.transmission = transmission

def change_transporting_type(self, body):
self.body = body

def change_weight(self, weight_over_3_tons=bool):
self.weight_over_3_tons = weight_over_3_tons

def color(self, color):
self.color = color
print(self.color)
26 changes: 21 additions & 5 deletions Classes/mashine/Passenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
from mashine.car import Car


class Passenger(Car):
def __init__(self, first_name, last_name="Passenger Car", body="passenger", engine="gasoline",
class Passengers(Car):
"""Класс Пассажирская(Машина) P.s.в англ. языке слово Пасажирская пишется как Passenger`s но называть класс так нельзя поэтому Passengers"""

def __init__(self, car_name, class_name="Passengers Car", body="passengers", engine="gasoline",
shassis="front_wheel", transmission="manual", weight_over_3_tons=False):
self.first_name = first_name
self.last_name = last_name
super().__init__(car_name, class_name)
self.car_name = car_name
self.class_name = class_name
self.body = body
self.engine = engine
self.shassis = shassis
self.transmission = transmission
self.weight_over_3_tons = weight_over_3_tons
"""car_name - Название машины, class_name - класс машины(пассажирская,грузовая)"""

def drive(self):
self.min = 0
if self.engine == "gasoline" and self.shassis == "front_wheel" and self.transmission == "manual":
"""Если машина классической сборки то шансы на поломку(не возможность ехать)меньше"""
self.min -= 3
self.max = 1
if self.engine == "gasoline" and self.shassis == "front_wheel" and self.transmission == "manual":
Expand All @@ -33,12 +38,23 @@ def can_transport_cargo(self):
else:
print("The car can transporting cargo.")

def can_transport_passenger(self):
def can_transport_passengers(self):
if not self.weight_over_3_tons:
print("The car can transporting pessengers.")
else:
print("The car can`t transporting pessengers.")

def change_assembly(self, engine, shassis, transmission):
self.engine = engine
self.shassis = shassis
self.transmission = transmission

def change_transporting_type(self, body):
self.body = body

def change_weight(self, weight_over_3_tons=bool):
self.weight_over_3_tons = weight_over_3_tons

def color(self, color):
self.color = color
print(self.color)
Binary file modified Classes/mashine/__pycache__/Cargo.cpython-37.pyc
Binary file not shown.
Binary file modified Classes/mashine/__pycache__/Passenger.cpython-37.pyc
Binary file not shown.
Binary file modified Classes/mashine/__pycache__/car.cpython-37.pyc
Binary file not shown.
30 changes: 15 additions & 15 deletions Classes/mashine/car.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import random as rnd

class Car:
def __init__(self, first_name, last_name="Car"):
self.first_name = first_name
self.last_name = last_name
def __init__(self, car_name, class_name="Car"):
self.car_name = car_name
self.class_name = class_name
self.lists = []
def drive(self):
self.breaking = rnd.randint(0, 1)
Expand All @@ -12,19 +12,19 @@ def drive(self):
else:
print("The car can`t be drive.")

def can_transport_cargo(self):
self.can_transport_cargo = rnd.randint(0, 1)
if self.can_transport_cargo == 0:
print("The car can transporting cargo")
else:
print("The car can`t transporting cargo")
#def can_transport_cargo(self):
#self.can_transport_cargo = rnd.randint(0, 1)
#if self.can_transport_cargo == 0:
#print("The car can transporting cargo")
#else:
#print("The car can`t transporting cargo")

def can_transport_pessenger(self):
self.can_transport_pessenger = rnd.randint(0, 1)
if self.can_transport_pessenger == 0:
print("The car can transporting pessengers")
else:
print("The car can`t transporting pessengers")
#def can_transport_pessenger(self):
#self.can_transport_pessenger = rnd.randint(0, 1)
#if self.can_transport_pessenger == 0:
#print("The car can transporting pessengers")
#else:
#print("The car can`t transporting pessengers")

def top_transport(self, word="Write you own top of car"):
self.word = word
Expand Down
6 changes: 3 additions & 3 deletions Classes/mashine/test_cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class TestCar(unittest.TestCase):
def test_chance_to_drive(self):
Cargo.__init__(Cargo, "Gaz", "Cargo", "cargo", "gasoline", "four_wheel", "manual", True)
Cargo.drive(Cargo)
print(Cargo.first_name + " " + Cargo.last_name)
print(Cargo.car_name + " " + Cargo.class_name)
print(Cargo.body)
print(Cargo.engine)
print(Cargo.shassis)
Expand All @@ -14,7 +14,7 @@ def test_chance_to_drive(self):
print(Cargo.max)
Cargo.__init__(Cargo, "Maz", "Cargo", "cargo", "diesel", "four_wheel", "auto", True)
Cargo.drive(Cargo)
print(Cargo.first_name + " " + Cargo.last_name)
print(Cargo.car_name + " " + Cargo.class_name)
print(Cargo.body)
print(Cargo.engine)
print(Cargo.shassis)
Expand All @@ -27,7 +27,7 @@ def test_weight_over_3_tons(self):
first = Cargo.weight_over_3_tons
Cargo.weight_over_3_tons = False
second = Cargo.weight_over_3_tons
Cargo.can_transport_pessenger(Cargo)
Cargo.can_transport_pessengers(Cargo)
Cargo.can_transport_cargo(Cargo)
self.assertEqual(first, second)

Expand Down
29 changes: 15 additions & 14 deletions Classes/mashine/test_passenger.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import unittest
from mashine.Passenger import Passenger
from mashine.Passenger import Passengers

class TestCar(unittest.TestCase):
def test_weight_over_3_tons(self):
Passenger.__init__(Passenger, "Oda", "Pessenger", "pessenger", "gasoline", "front_wheel", "manual", True)
first = Passenger.weight_over_3_tons
print(Passenger.weight_over_3_tons)
Passenger.weight_over_3_tons = False
print(Passenger.weight_over_3_tons)
second = Passenger.weight_over_3_tons
Passenger.can_transport_pessenger(Passenger)
Passenger.can_transport_cargo(Passenger)
Passengers.__init__(Passengers, "Oda", "Pessengers", "pessengers", "gasoline", "front_wheel", "manual", True)
first = Passengers.weight_over_3_tons
print(Passengers.weight_over_3_tons)
Passengers.weight_over_3_tons = False
print(Passengers.weight_over_3_tons)
second = Passengers.weight_over_3_tons
Passengers.can_transport_pessengers(Passengers)
Passengers.can_transport_cargo(Passengers)
self.assertEqual(first, second)

def test_color(self):
first = input("First Car Color: ")
second = input("Inter Word to Compare: ")
Passenger.color(Passenger, first)
self.assertNotEqual(first, int)
self.assertNotEqual(first, None)
self.assertNotEqual(first, float)
self.assertNotEqual(first, list)
Passengers.color(Passengers, first)
self.assertEqual(first, second)

#def test_weight(self):
#first = input("Inter Word to Compare: ")
#Passengers.change_weight(Passengers, first)
#self.assertEqual(first, True)

if __name__ == '__name__':
unittest.main()

0 comments on commit 7337f11

Please sign in to comment.