---
# System prepended metadata

title: ch13

---

# ch13
```javascript=
package ch13_1411031012;

import java.util.Scanner;

class bookcase { // 書櫃類別
	public static int total;  // 目前書櫃的數目
	public bookcase() { // 建構子		
		total++;
	}
}


class book extends bookcase { // 書類別
	public static int total=0;  // 目前書的數目
	private String title; // 書名
	public double price;       // 價格
	public book(String z, double c) { // 建構子( 從外部傳進來)
		title = z;
		price = c;
		total++;
	}
	public String getTitle() {//回傳字串
		return title;
	}
	public double getPrice() {//回傳數值
		return price;
	}
	public double raisePrice(double price) {//回傳計算完的數值
		double sum=price*0.1;
		return sum;
	}
	
	public void showData() {
		System.out.println("新增書籍[" + title + "],訂價" + price+"元");
		//System.out.println("飛機編號:" + id + " 引擎號碼:" + engineId);
		//System.out.print("飛行員人數:" + pilotNum + " 油箱容量(L):" + fuelTank);
	}
}
public class ex2 {	
	
	
	public static void main(String[] args) {
		
		book b1 = new book("Java程式設計", 300.5);
		double aa = 0;
		b1.getTitle();
		b1.getPrice();
		b1.raisePrice(aa);
		//System.out.println(b1.raisePrice(aa));
		
		book b2 = new book("資料庫管理系統", 450.6);
		b1.getTitle();
		b1.getPrice();
	//	b1.raisePrice();
	
	}
	
}

```
```javascript=
package t;
import java.util.Scanner;

class Book{ // 書類別
	public static int total=0;  // 目前書的數目
	private String title; // 書名
	private double price;       // 價格 ->private
	public Book(String z, double c) { // 建構子( 從外部傳進來)
		title = z;
		price = c;
		total++;
	}
	public String getTitle() {//回傳字串
		return title;
	}
	public double getPrice() {//回傳數值
		return price;
	}
	public double raisePrice(double price) {//回傳計算完的數值
		this.price += price;
		return this.price;
	}
}
public class ex2 {	
	
	
	public static void main(String[] args) {
		double aa = 300.5;
		String bb= "Java程式設計";
		Book b1 = new Book(bb, aa);
		System.out.println(b1.getTitle());
		System.out.println(b1.getPrice());
		b1.raisePrice(aa*0.1);
		System.out.println(b1.getPrice());
		//System.out.println(b1.raisePrice());
		System.out.println(Book.total);
		
		Book b2 = new Book("資料庫管理系統", 450.6);
		System.out.println(b2.getTitle());
		System.out.println(b2.getPrice());
		b2.raisePrice(50.0);
		System.out.println(b2.getPrice());
		System.out.println(Book.total);
	}
	
}

```
