永发信息网

请JAVA高手帮忙编一下这个程序~谢

答案:3  悬赏:30  手机版
解决时间 2021-04-20 01:12
  • 提问者网友:树红树绿
  • 2021-04-19 17:54

定义类和创建对象

设计一个活期存折类,其中属性包括姓名name(string类型),身份证号indentity-Card(string类型),家庭住址homeAddress(string类型),钱数money(double类型),定义显示存折人基本信息的show方法。再定义一个测试类,在main方法中使用活期存折类创建一个活期存折对象,其属性值分别为张三(姓名),1234567890(身份证号),教育学院(地址),1000(钱数),最后显示该存折的基本信息。

最佳答案
  • 五星知识达人网友:白昼之月
  • 2021-04-19 18:18


class Discount {
private String name;
private String identifyCard;
private String homeAddress;
private double money;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIdentifyCard() {
return identifyCard;
}
public void setIdentifyCard(String identifyCard) {
this.identifyCard = identifyCard;
}
public String getHomeAddress() {
return homeAddress;
}
public void setHomeAddress(String homeAddress) {
this.homeAddress = homeAddress;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}

public String show(){
StringBuilder sb = new StringBuilder();
sb.append("姓名:").append(name).append("\n");
sb.append("身份证号:").append(identifyCard).append("\n");
sb.append("家庭地址:").append(homeAddress).append("\n");
sb.append("存款数:").append(money).append("\n");
return sb.toString();
}
}

public class DiscountTest{
public static void main(String[] args) {
Discount discount = new Discount();
discount.setName("张三");
discount.setHomeAddress("教育学院");
discount.setIdentifyCard("1234567890");
discount.setMoney(1000);

System.out.println(discount.show());
}
}
全部回答
  • 1楼网友:不如潦草
  • 2021-04-19 21:08

class Discount { private String name; private String identifyCard; private String homeAddress; private double money; public Discount(String name,String identifyCard,String homeAddress,double money) { this.name=name; this.identifyCard=identifyCard; this.homeAddress=homeAddress; this.money=money; } void show() { System.out.println(this.name); System.out.println(this.identifyCard); System.out.println(this.homeAddress); System.out.println(this.money); } } class test { public static void main(String ag[]) { Discount d=new Discount("张三","1234567890","教育学院","1000"); d.show(); } }

我用的构造函数,你看看

  • 2楼网友:慢性怪人
  • 2021-04-19 19:32

接着楼上写

public String show(){

return this.Name + "\n" + this.IdentityCard +"\n" + this.HomeAddress + "\n" + this.Money }

Discount discount = new Discount(); discount.setName("张三"); discount.setHomeAddress("教育学院"); discount.setIdentifyCard("1234567890"); discount.setMoney(1000); System.out.println(discount.show());

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯