120 likes | 224 Views
Introduction to Java. Week 7 Mobile Phone Library, EasyIn & Command-line IO. Case Study on Mobiles. Mobile phone library New directory/workspace, eg mobile Class definition file MobileNumber.java Demonstration file MobileNumberDemonstration.java
E N D
Introduction to Java Week 7 Mobile Phone Library, EasyIn & Command-line IO
Case Study on Mobiles • Mobile phone library • New directory/workspace, eg mobile • Class definition file MobileNumber.java • Demonstration file MobileNumberDemonstration.java • Client demonstration must include main method, to execute
MobileNumber class • MobileNumber String number String name String getNumber() void setNumber( String ) String getName() void setName( String )
Compilation order • Compile class definition file • Compile class demonstration file next (dependency) • Both compile into .class files • Run demonstration program (main) • (Note: child classes are dependent on their parents and have to be compiled first)
MobileWorld & JCreator • To use Workspace facility: • Create a new workspace/ directory • Download the files into the workspace directory • Compile files • If more than one demo program file with main, execute file required only
Demo program • Executable program class must have:public static void main( String[] args) { • To output to command-line:System.out.println( ”Call timed at ..." + getTime() ); • System library part of Java API
Utility class MobileTime • Calls display time in hh:mm (so do alarm calls, reminders etc) • Create utility class • Stores time as int (minutes since midnight) • Convert for display • Note: no checking or validation
MobileTime contents • MobileTime int timeInMinutes int getTime() String getFormattedTime() void setTime(int) • Plus private methods needed to format as hh:mm
EasyIn utility class • In C&K text book • In MobileTime demo:timeInt = EasyIn.getInt(); • Note class call to static method • Also includesgetStringgetDoublepause etc
PhoneCall class • PhoneCall aggregates MobileTime callTime MobileNumber callNumber MobileTime getTime() MobileNumber getNumber • Demo uses EasyIn
Summary • New library of related classes • Mobile classes • Utility classes • Demo programs to test new classes • Command-line IO • Simulations of mobile phone functions