编写程序一个shu类,用于描述个人藏书,包括作者zuozhe、书名 shuming、价格 jiage、出版社 chubanshe、出版年份 chubannianfen共5个属性。然后编写一个测试类 cheshilei,对 shu类进行测试,输出正确的属性值。
时间: 2023-12-14 17:36:48 浏览: 86
下面是一个简单的实现:
```java
public class Shu {
private String zuozhe;
private String shuming;
private double jiage;
private String chubanshe;
private int chubannianfen;
public Shu(String zuozhe, String shuming, double jiage, String chubanshe, int chubannianfen) {
this.zuozhe = zuozhe;
this.shuming = shuming;
this.jiage = jiage;
this.chubanshe = chubanshe;
this.chubannianfen = chubannianfen;
}
public String getZuozhe() {
return zuozhe;
}
public String getShuming() {
return shuming;
}
public double getJiage() {
return jiage;
}
public String getChubanshe() {
return chubanshe;
}
public int getChubannianfen() {
return chubannianfen;
}
}
```
测试类:
```java
public class Cheshilei {
public static void main(String[] args) {
Shu shu = new Shu("张三", "Java编程思想", 99.9, "机械工业出版社", 2018);
System.out.println("作者:" + shu.getZuozhe());
System.out.println("书名:" + shu.getShuming());
System.out.println("价格:" + shu.getJiage());
System.out.println("出版社:" + shu.getChubanshe());
System.out.println("出版年份:" + shu.getChubannianfen());
}
}
```
输出:
```
作者:张三
书名:Java编程思想
价格:99.9
出版社:机械工业出版社
出版年份:2018
```
阅读全文