package c5 class Counter { private var value = 0 def increment(){ if(value < Int.MaxValue){ value += 1 } } def current() = value } class BankAccount{ val balance = 0 def deposit(amount:Double){} def withdraw(){} } class Time(val hours:Int,val minutes:Int){ def before(other:Time):Boolean = { hours < other.hours || (hours == other.hours && minutes < other.minutes) } override def toString: String = {hours + ":" + minutes} } class Time1(val hours:Int,val minutes:Int){ def before(other:Time):Boolean = { hours < other.hours || (hours == other.hours && minutes < other.minutes) } override def toString: String = {hours * 60 + minutes + ""} } import java.beans.BeanProperty import scala.beans.BeanProperty/*查找包位置*/ class Student{ @BeanProperty var name:String = _ @BeanProperty var id:Long = _ } /*p06*/ class Person(var age:Int){age = if(age < 0)0 else age} /*p07*/ class Person1(val name:String){ val (firstname,lastname) = name.split(" ") } /*p08*/ class Car(val maker:String,val typename:String){ private var typeyear:Int = -1 private var Board:String = "" def this(maker:String,typename:String,typeyear:Int,Board:String){ this() this.typeyear=typeyear this.Board=Board } } /*p10*/ class Employ(){ val name:String = "John Q.Public" var salary:Double = 0.0 }