Advertisement
jinshiyi

Untitled

Dec 11th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.31 KB | None | 0 0
  1. //This is my code.
  2. data class PriceInfo (
  3.     val ratePerTimeUnit: String,
  4.     // ratePerMonth is ratePerTimeUnit*24*30
  5.     val ratePerMonth: String,
  6.     // ratePerYear is ratePerTimeUnit*24*365
  7.     val ratePerYear: String,
  8. }
  9. //Ivo's comments
  10. Does this really need to be optional? Yes for ECS we need to calculate it, but if we always calculate it, then we know that it will always be there, right?
  11. We could even move the calculation into this data class, possibly in the constructor even -- as you need to supply the rateTimePerUnit anyway?
  12. //Does he mean to write like this?
  13. data class PriceInfo (
  14.     val ratePerTimeUnit: String,
  15.     // ratePerMonth is ratePerTimeUnit*24*30
  16.     val ratePerMonth: String = String.format("%.2f",(Double.parseDouble(ratePerTimeUnit) * 24.0 * 30.0)),
  17.     // ratePerYear is ratePerTimeUnit*24*365
  18.     val ratePerYear: String = String.format("%.2f",(Double.parseDouble(ratePerTimeUnit) * 24.0 * 365.0))
  19. }
  20. //But how to write the code about create new PriceInfo
  21. val PriceInfo = PriceInfo( 10.0, ?, ?)
  22. //Or like this
  23. data class PriceInfo (
  24.     val ratePerTimeUnit: String
  25. ){
  26.     val ratePerMonth: String = String.format("%.2f",(Double.parseDouble(ratePerTimeUnit) * 24.0 * 30.0))
  27.     val ratePerYear: String = String.format("%.2f",(Double.parseDouble(ratePerTimeUnit) * 24.0 * 365.0))
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement