INFO1113 - Week6 Notes

Lecture

  • Part A: Abstract Classes, Abstract Classes UML, Interfaces Interfaces and UML
  • Part B: Default method in Interfaces, Packaging

Abstract Class

  • Can define methods and attributes
  • Cannot be instantiated
// Declaration
[modifier] abstract class ClassName

// Abstract methods
public static void stack (ClassName element);

Interfaces

  • Attributes must be static / constant
  • Cannot be instantiated
  • Interface is not a class
// Declaration
[modifier] interface InteraceName
  • Default method
[modifier] default <returntype> MethodName([parameters])

Subclass can override the default method

Organising

  • Classpath: defines a set of dictories exposed to the program
  • Packages
package <identifier>[.<nested ident>[...]]
  • Java Archives

Tutorial

  • Packages:
package my.library

javac -cp .:<directory to .class/.java files> Program.java
java -cp .:<directory to .class files> Program

  • Archive

jar -cfm manifest.txt project.jar project/*.class

Challenges

  • rounding to 2 decimal place
// Method 1
String toTwoDP = String.format("%.2f",test.cost());
// 1.998 => 2.00

// Method 2 - not always the case
DecimalFormat df = new DecimalFormat("#.##");
String toTwoDP = df.format(test.cost());
// 2.001 => 2
// 2.345 => 2.35

// Method 3
System.out.printf("This trip will cost $%.02f %n",test.cost());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值