用Java编写一个图书类程序:1.属性:图书编号,图书名称,出版社,库存量。2.构造方法:至少两个
用Java编写一个图书类程序:1.属性:图书编号,图书名称,出版社,库存量。2.构造方法:至少两个。3.方法:输图书信息,输出图书信息,修改库存量...
用Java编写一个图书类程序:1.属性:图书编号,图书名称,出版社,库存量。2.构造方法:至少两个。3.方法:输图书信息,输出图书信息,修改库存量
展开
展开全部
package com.hua.excep;
public class Libary {
private int id;
private String name;
private String shop;
private int num;
//两个构造方法
//无参
public Libary() {
}
//四个参数
public Libary(int id, String name, String shop, int num) {
this.id = id;
this.name = name;
this.shop = shop;
this.num = num;
}
//输入图书信息
public void inputBook(int id,String name,String shop){
this.id=id;
this.name=name;
this.shop=shop;
}
//输出三个图书信息
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getShop() {
return shop;
}
//修改库存
public void setNum(int num) {
this.num = num;
}
}
public class Libary {
private int id;
private String name;
private String shop;
private int num;
//两个构造方法
//无参
public Libary() {
}
//四个参数
public Libary(int id, String name, String shop, int num) {
this.id = id;
this.name = name;
this.shop = shop;
this.num = num;
}
//输入图书信息
public void inputBook(int id,String name,String shop){
this.id=id;
this.name=name;
this.shop=shop;
}
//输出三个图书信息
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getShop() {
return shop;
}
//修改库存
public void setNum(int num) {
this.num = num;
}
}
展开全部
public class $ {
public static void main(String[] args) {
Book e = new Book("1", "aaa", "出版社");
e.out();
e.in("出版社", 50);
e.out();
e.select();
// 修改库存量
e.setCount(100);
e.out();
}
}
class Book {
private String no;
private String name;
private String press;
private int count;
public Book(String no, String name, String salary) {
this.no = no;
this.name = name;
this.press = salary;
}
public Book(String no, String name, String salary, int bonus) {
this.no = no;
this.name = name;
this.press = salary;
this.count = bonus;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBonus() {
return count;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public void out() {
System.out.println(no + "," + name + "," + press + "," + count);
}
public void in(String press, int count) {
this.press = press;
this.count = count;
}
public void select() {
System.out.println(count);
}
}
追问
不对啊,第一部
追答
什么第一步?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询