fork download
  1. public class DVD {
  2. int rent_days;//預計出租天數
  3. String title;//dvd片名
  4. int charge_rate;//dvd每天租金
  5. static int fine_rate;//逾期後每天罰金
  6.  
  7. DVD (String title, int charge_rate){
  8. this.title=title;
  9. this.charge_rate=charge_rate;
  10. }
  11.  
  12. void setFineRate(int rate){
  13. this.fine_rate=fine_rate;
  14. }
  15.  
  16. void rent(int rdays){//最多能租天數
  17. rent_days=rdays;
  18. }
  19.  
  20. int giveback(int gdays){//實際出租天數
  21. int pay;//應付金額
  22. if(gdays>rent_days)//假如逾期要付的金額
  23. {
  24. pay=rent_days*charge_rate+(gdays-rent_days)*fine_rate;
  25. }
  26. else//假如沒逾期
  27. {
  28. pay=gdays*charge_rate;
  29. }
  30. return pay;
  31. }
  32.  
  33. String getTitle(){//回傳片名
  34. return title;
  35. }
  36.  
  37. public static void main (String args[ ]){
  38. /*ABC租1天30,最高可租5天
  39.   DEF租1天50,最高可租3天
  40.   每部dvd逾期後每天罰70元
  41.   今天我ABC租了4天
  42.   DEF租了6天
  43.   要計算出每部的金額與總金額
  44.   */
  45. DVD dvd1=new DVD("ABC",30);
  46. DVD dvd2=new DVD("DEF",50);
  47. dvd1.setFineRate(70);
  48. dvd2.setFineRate(70);
  49. dvd1.rent(5);
  50. dvd2.rent(3);
  51. int money1,money2,total;
  52. money1=dvd1.giveback(4);
  53. money2=dvd2.giveback(6);
  54. total=money1+money2;
  55. System.out.println(dvd1 +":"+ money1 +"\n"+
  56. dvd2 +":"+ money2 +"\n"+
  57. "Total:"+ total);
  58. }
  59. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: class DVD is public, should be declared in a file named DVD.java
public class DVD {
       ^
1 error
stdout
Standard output is empty