- 
                Notifications
    
You must be signed in to change notification settings  - Fork 99
 
Homework #4 #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            mahonin-ms
  wants to merge
  3
  commits into
  Android-Developer-Basic:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
mahonin-ms:homework
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Homework #4 #67
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,4 +8,5 @@ interface CarOutput { | |
| * Скажи текущую скорость | ||
| */ | ||
| fun getCurrentSpeed(): Int | ||
| fun getFuelLevel(): Int | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package ru.otus.cars | ||
| 
     | 
||
| import java.lang.RuntimeException | ||
| 
     | 
||
| class FuelStation { | ||
| companion object { | ||
| 
     | 
||
| private lateinit var currentCar: Car | ||
| fun refuelCar(car: Car, litres: Int) { | ||
| println("Заправка авто: ${car.toString()} на ${litres.toString()} литров") | ||
| currentCar = car | ||
| if( currentCar is Taz){ | ||
| throw RuntimeException("ТАЗ НЕ УМЕЕТ ЗАПРАВЛЯТЬСЯ") | ||
| } | ||
| 
     | 
||
| val isOk = when(car.fuelSystem.tankMouth.type){ | ||
| Type.GAS, Type.FUEL -> { | ||
| addFuel(litres) | ||
| true | ||
| } | ||
| else -> { | ||
| println("Не обслуживаентся") | ||
| false | ||
| } | ||
| } | ||
| if(isOk) | ||
| println("Заправлено. Уровень топлива в авто: ${car.carOutput.getFuelLevel()} литров") | ||
| else | ||
| println("Не заправлено. Уровень топлива в авто: ${car.carOutput.getFuelLevel()} литров") | ||
| 
     | 
||
| println("") | ||
| 
     | 
||
| } | ||
| 
     | 
||
| private fun addFuel(litres: Int): Boolean { | ||
| return currentCar.fuelSystem.tankMouth.addFuel(litres) | ||
| } | ||
| 
     | 
||
| } | ||
| 
     | 
||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package ru.otus.cars | ||
| 
     | 
||
| /** | ||
| * Тип топлива: Бензин или Газ | ||
| */ | ||
| enum class Type{ | ||
| FUEL, GAS | ||
| } | ||
| interface Tank{ | ||
| var level: Int | ||
| } | ||
| 
     | 
||
| /** | ||
| * Горловина к топливному баку | ||
| */ | ||
| data class TankMouth(val type:Type, val tank:Tank){ | ||
| /** | ||
| * Заправка бака топливом через горловину | ||
| * @param level - сколько залить в бак | ||
| * @return сколько в баке после заправки | ||
| */ | ||
| fun addFuel(level: Int): Boolean { | ||
| val fuelLevelBefore = this.tank.level | ||
| this.tank.level += level | ||
| return (this.tank.level - fuelLevelBefore > 0) | ||
| } | ||
| } | ||
| 
     | 
||
| class FuelSystem { | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mahonin-ms идея объединить бак и горловину единой внешней сущностью - это хорошее решение! Но ссылка к машине, опять же, кажется лишней. В реальной жизни топливную систему в сборе ставят в машину. Горловина торчит наружу - это и есть интерфейс для заправки  | 
||
| private var tank:Tank // Топливный бак | ||
| var tankMouth: TankMouth // Горловина бака | ||
| constructor(fuelType:Type){ | ||
| when(fuelType){ | ||
| Type.FUEL -> { | ||
| this.tank = FuelTank() | ||
| } | ||
| Type.GAS -> { | ||
| this.tank = GasTank() | ||
| } | ||
| } | ||
| this.tankMouth = TankMouth(fuelType, this.tank) | ||
| } | ||
| } | ||
| 
     | 
||
| /** | ||
| * Реализация бака с бензином | ||
| * @version = 1.0 | ||
| */ | ||
| class FuelTank: Tank { | ||
| override var level = 0 | ||
| var type = "Бак с бензином" | ||
| } | ||
| 
     | 
||
| /** | ||
| * Реализация бака с газом | ||
| * @version = 1.0 | ||
| */ | ||
| class GasTank: Tank{ | ||
| override var level = 0 | ||
| var type = "Бак с газом" | ||
| } | ||
| 
     | 
||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -20,6 +20,7 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { | |
| override fun build(plates: Car.Plates): Vaz2107 = Vaz2107("Зеленый").apply { | ||
| this.engine = getRandomEngine() | ||
| this.plates = plates | ||
| this.fuelSystem = FuelSystem(Type.GAS) | ||
| } | ||
| 
     | 
||
| /** | ||
| 
        
          
        
         | 
    @@ -39,7 +40,6 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { | |
| // Переопределяем свойство родителя | ||
| override lateinit var engine: VazEngine | ||
| private set | ||
| 
     | 
||
| /** | ||
| * Семерка едет так | ||
| */ | ||
| 
        
          
        
         | 
    @@ -59,20 +59,32 @@ class Vaz2107 private constructor(color: String) : VazPlatform(color) { | |
| 
     | 
||
| // Выводим состояние машины | ||
| override fun toString(): String { | ||
| return "Vaz2107(plates=$plates, wheelAngle=$wheelAngle, currentSpeed=$currentSpeed)" | ||
| return "Vaz2107(plates=$plates, wheelAngle=$wheelAngle, currentSpeed=$currentSpeed, " + | ||
| "fuelType=${fuelSystem.tankMouth.type}, fuelLevel=${fuelSystem.tankMouth.tank.level})" | ||
| } | ||
| 
     | 
||
| /** | ||
| * Делегируем приборы внутреннему классу | ||
| */ | ||
| override val carOutput: CarOutput = VazOutput() | ||
| 
     | 
||
| /** | ||
| * Топливная система ВАЗ 2107 | ||
| */ | ||
| override lateinit var fuelSystem: FuelSystem | ||
| private set | ||
| 
     | 
||
| /** | ||
| * Имеет доступ к внутренним данным ЭТОГО ВАЗ-2107! | ||
| */ | ||
| inner class VazOutput : CarOutput { | ||
| override fun getCurrentSpeed(): Int { | ||
| return [email protected] | ||
| } | ||
| 
     | 
||
| override fun getFuelLevel(): Int { | ||
| return [email protected] | ||
| } | ||
| 
     | 
||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -21,6 +21,7 @@ class Vaz2108 private constructor(color: String) : VazPlatform(color) { | |
| override fun build(plates: Car.Plates): Vaz2108 = Vaz2108("Красный").apply { | ||
| this.engine = getRandomEngine() | ||
| this.plates = plates | ||
| this.fuelSystem = FuelSystem(Type.FUEL) | ||
| } | ||
| 
     | 
||
| fun alignWheels(vaz2108: Vaz2108) { | ||
| 
          
            
          
           | 
    @@ -63,13 +64,16 @@ class Vaz2108 private constructor(color: String) : VazPlatform(color) { | |
| 
     | 
||
| // Выводим состояние машины | ||
| override fun toString(): String { | ||
| return "Vaz2108(plates=$plates, wheelAngle=$wheelAngle, currentSpeed=$currentSpeed)" | ||
| return "Vaz2108(plates=$plates, wheelAngle=$wheelAngle, currentSpeed=$currentSpeed, " + | ||
| "fuelType=${fuelSystem.tankMouth.type}, fuelLevel=${fuelSystem.tankMouth.tank.level}" | ||
| } | ||
| 
     | 
||
| /** | ||
| * Делегируем приборы внутреннему классу | ||
| */ | ||
| override val carOutput: CarOutput = VazOutput() | ||
| override lateinit var fuelSystem: FuelSystem | ||
| private set | ||
| 
     | 
||
| /** | ||
| * Имеет доступ к внутренним данным ЭТОГО ВАЗ-2108! | ||
| 
        
          
        
         | 
    @@ -78,5 +82,9 @@ class Vaz2108 private constructor(color: String) : VazPlatform(color) { | |
| override fun getCurrentSpeed(): Int { | ||
| return [email protected] | ||
| } | ||
| 
     | 
||
| override fun getFuelLevel(): Int { | ||
| return [email protected] | ||
| } | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mahonin-ms, получился костыль в заправке. Почему бы не сделать взрыв непосредственно в ТАЗу? Зачем другим компонентам знать "детали его внутренней реализации"?