第四周课程总结&试验报告(二)

1.写一个名为Rectangle的类表示矩形。其属性包括宽width、高height和颜色color,width和height都是double型的,而color则是String类型的。要求该类具有:

(1) 使用构造函数完成各属性的初始赋值

(2) 使用get…()和set…()的形式完成属性的访问及修改

(3) 提供计算面积的getArea()方法和计算周长的getLength()方法
实验代码

package 实验报告2;

public class 作业1 {
    public class Rectangle {
        private double height;
        private double width;
        private String color;
        public double getHeight() {
        return height;
        }
        public void setHeight(double height) {
        this.height = height;
        }
        public double getWidth() {
        return width;
        }
        public void setWidth(double width) {
        this.width = width;
        }
        public String getColor() {
        return color;
        }
        public void setColor(String color) {
        this.color = color;
        }
        public Rectangle(double width,double height,String color){
        this.setColor(color);
        this.setHeight(height);
        this.setWidth(width);
        }
        public void getArea(){
        double area=0;
        area=this.height*this.width;
        System.out.println("矩形的面积为"+area);
        }
        public String toString(){
        String recStr="矩形的高度:"+this.getHeight()+"宽度:"+this.getWidth()
        +"颜色:"+this.getColor();
        return recStr;
        }
    
        public static void main(String[] args) {
        Rectangle rec=new Rectangle(3, 4, "红色");
        rec.getArea();
        System.out.println(rec.toString());
        }
    }
}
    

一开始不会做遇到了这个问题后来到网上搜还是遇到这个问题 ,还是没有搞懂
1581803-20190919145856945-1731509233.png

2.银行的账户记录Account有账户的唯一性标识(11个长度的字符和数字的组合),用户的姓名,开户日期,账户密码(六位的数字,可以用0开头),当前的余额。银行规定新开一个账户时,银行方面提供一个标识符、账户初始密码123456,客户提供姓名,开户时客户可以直接存入一笔初始账户金额,不提供时初始余额为0。定义该类,并要求该类提供如下方法:存款、取款、变更密码、可以分别查询账户的标识、姓名、开户日期、当前余额等信息。
实验代码

import java.util.Date;
import java.util Scanner;
public class bank
{
    private String id;
    private String name;
    private double createtime;
    private String password;
    private int money;
    
    public amount(String id,String name,int money)
    {
        this.setID(id);
        this.setName(name);
        this.setMoney(money);
        this.setPassword="123456";
        this.setCreatetime = new Date();
    }
    public int deposit()
    {
        return money+amount;
    }
    public int withdraw()
    {
        return amount-money;
    }
    public void setCreatetime(int s)
    {
        createtime = s;
    }
    public int getcreatetime()
    {
        return createtime;
    }
    public void changepassword()
    {
      Scanner x = new Scanner(System.in);
      System.out.println("输入新的密码:");
      String password = x.nextString();
      this.password = new password;
    }
    public static void main(String [] args)
    {
        Bank n = new bank("id","name","createtime");
        System.out.println("账号:"+n.getID());
        System.out.println("姓名:"+n.getName());
        System.out.println("开户日期:"+n.getCreatetime());
        System.out.println("余额:"+n.getAmont());
    }
}

总感觉 出了好多问题 按照网上方法来修改 还是有问题
1581803-20190919153625771-675381509.png

感觉Java好难啊 不像c以前按照书一章一章来学 Java跳跃性好大

转载于:https://www.cnblogs.com/liualiu/p/11550136.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值