Write Java applications. First, define a clock class--clock, which consists of three int types
Member variables represent hours, minutes, seconds, and a construction method for three member variables (hours, minutes, seconds)
For initialization, there is also a member method show () to display the time of the clock object. Second, redefine
A main class,TestClass, creates objects of multiple clock classes in the main method of themaster Class , using this
Some objects call the method show () to display the time of the clock.
Public classClock {inthour; intmin; intsec; Clock (intHintMints) { This. hour=h; This. min=m; This. sec=s; } voidShou () {if(hour>=0&&hour<24) && (min>=0&&min<60) && (sec>=0&&sec< 60)) System.out.println (Hour+ ":" +min+ ":" +sec); ElseSystem.out.println ("Time entered is incorrect"); } Public Static voidMain (string[] args) {Clock Shijian=NewClock (12,30,45); Clock Shijian1=NewClock (25,20,61); Clock shijian2=NewClock (8,15,59); Shijian.shou (); Shijian1.shou (); Shijian2.shou (); }}
Write Java applications. First, define an account class that describes the bank accounts , including the member changes
Amount "Account" and "Deposit balance", the Member method has "deposit", "withdrawal" and "balance inquiry". Secondly
Write a main class that tests the function of the account class in the main class.
Public classAccount {String Zhanghao; DoubleYuE; Account (String Zhanghao,DoubleYuE) { This. zhanghao=Zhanghao; This. Yue=YuE; } DoubleCunkuan (DoubleQianshu) { if(qianshu<0) System.out.println ("Money Error"); Else This. yue+=Qianshu; return This. YuE; } voidQukuan (DoubleQianshu) { if(qianshu> This. YuE) {System.out.println ("Insufficient balance"); return; } This. yue-=Qianshu; } DoubleGetyue () {return This. YuE; } Public Static voidMain (string[] args) {Account AC=NewAccount ("123456", 1000); Ac.cunkuan (500); System.out.println ("Balance" +Ac.getyue ()); Ac.qukuan (300); System.out.println ("Balance" +Ac.getyue ()); Ac.cunkuan (-200); System.out.println ("Balance" +Ac.getyue ()); Ac.qukuan (2000); System.out.println ("Balance" +Ac.getyue ()); }}
Java classes and Object Foundation questions