zoukankan      html  css  js  c++  java
  • 第四周课程总结&试验报告(二)

    题目一:
    写一个名为Rectangle的类表示矩形。其属性包括宽width、高height和颜色color,width和height都是double型的,而color则是String类型的。要求该类具有:
    (1) 使用构造函数完成各属性的初始赋值

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

    (3) 提供计算面积的getArea()方法和计算周长的getLength()方法
    实验代码:
    '''
    public class Rectangle {
    private String color;
    private double width;
    private double height; //定义属性
    public void setColor(String color) { //设置颜色
    this.color=color;
    }
    public void setWidth(double width) { //设置宽度
    this.width=width;
    }
    public void setHeight(double height) { //设置高度
    this.height=height;
    }
    public String getColor() { //取得颜色
    return color;
    }
    public double getWidth() { //取得宽度
    return width;
    }
    public double getHeight() { //取得高度
    return height;
    }
    public double getArea() { //求矩形面积
    return widthheight;
    }
    public double getLength() { //求矩形周长
    return 2
    (width+height);
    }
    public static void main(String args[]) {
    Rectangle r=new Rectangle();
    r.setWidth(10);
    r.setHeight(5);
    System.out.println(r.getArea()); //输出面积
    System.out.println(r.getLength()); //输出周长
    }

    }
    '''

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

    实验代码:
    '''
    import java.util.;
    public class Account {
    public String getId() {
    return id;
    }
    public void setId(String id) {
    this.id = id;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    /

    public String getDate() {
    return date;
    }
    public void setDate(String date) {
    this.date = date;
    }
    /
    public String getPassword() {
    return password;
    }
    public void setPassword(String password) {
    this.password = password;
    }
    public double getBalance() {
    return balance;
    }
    public void setBalance(double balance) {
    this.balance = balance;
    }
    public static String getRandomNumbersAndString(int length) {
    String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
    return getRandomString(length, base);
    }
    private static String getRandomString(int length, String base) {
    Random random = new Random();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < length; i++) {
    int number = random.nextInt(base.length());
    sb.append(base.charAt(number));
    }
    return sb.toString();
    }
    /
    private static String getUniqueRandomString(int length, String base) {
    // TODO Auto-generated method stub
    return null;
    }*/
    //private Date date = new Date();

        private String id = getRandomNumbersAndString(11);
        private String name;
        private String password = "123456";
        private double balance;
        public  Account(String name,double balance) {
            this.setName(name);
            this.setBalance(balance);
        }
        public Account() {
            
        }
        public double Deposit(double n) {
            this.balance = balance + n;
            return balance;
        }
        public double Draw(double m) {
            this.balance = balance - m;
            return balance;
        }
        public String Changepassword(String password) {
            this.password = password;
            return password;
        }
    }
    
    import java.util.*;
    public class Example2 {
        public static void main(String args[]) {
            Account huang = null;
            huang = new Account("。。。。。。。。",0);
            Date date = new Date();
            Scanner in= new Scanner(System.in);
            Scanner sr = new Scanner(System.in);
            String str;
            System.out.println("输入相应的英文进行操作。。。。。。。。");
            while(true) {
            str = in.nextLine();
            if(str == "exit") {
                break;
            }
            switch(str) {
            case "Deposit":{
                double n = in.nextDouble();
                System.out.println("用户的余额还有:"+huang.Deposit(n));
                System.out.println("输入exit结束程序。。。。。。");
                break;
            }
            case "Draw":{
                double n = in.nextDouble();
                System.out.println("用户的余额剩余:"+huang.Draw(n));
                System.out.println("输入exit结束程序。。。。。。");
                break;
            }
            case "Changepassword":{
                String str2;
                str2 = in.nextLine();
                System.out.println("用户的密码改为:"+huang.Changepassword(str2));
                System.out.println("输入exit结束程序。。。。。。");
                break;
            }
            case "date":{
                System.out.println("用户的开户日期为:"+date);
                System.out.println("输入exit结束程序。。。。。。");
                break;
            }
            case "id":{
                System.out.println("用户标识为:"+huang.getId());
                System.out.println("输入exit结束程序。。。。。。");
                break;
            }
            case "name":{
                System.out.println("用户的姓名为:"+huang.getName());
                System.out.println("输入exit结束程序。。。。。。");
                break;
            }
            case "balance":{
                System.out.println("用户的当前余额为:"+huang.getBalance());
                System.out.println("输入exit结束程序。。。。。。");
                break;
            }
            case "exit":{
                System.exit(0);
                System.out.println("程序关闭正常");
            }
            default:{
                System.out.println("输入错误请重新输入:");
                System.out.println("输入exit结束程序。。。。。。");
                break;
            }
            }
            }
            /*System.out.println(yonghu.getId());
            System.out.println(date);*/
            in.close();
            sr.close();
        }
    
    }
    

    }
    '''

    实验报告总结:
    两个题目都不太会做,有点懵,一次次的没有结果也查不出哪错了,查找资料询问同学也弄那个不出来,希望老师能够解释下怎么加main方法,如何编译谢谢。

    第四周课程总结:
    1.加强学习了String类的灵活运用。
    2.同时学习了main方法的运用及this关键词。
    3.拓展了import关键字和Scanner类的灵活用法。
    4.继续撸起袖子加油干。

  • 相关阅读:
    Note/Solution 转置原理 & 多点求值
    Note/Solution 「洛谷 P5158」「模板」多项式快速插值
    Solution 「CTS 2019」「洛谷 P5404」氪金手游
    Solution 「CEOI 2017」「洛谷 P4654」Mousetrap
    Solution Set Border Theory
    Solution Set Stirling 数相关杂题
    Solution 「CEOI 2006」「洛谷 P5974」ANTENNA
    Solution 「ZJOI 2013」「洛谷 P3337」防守战线
    Solution 「CF 923E」Perpetual Subtraction
    KVM虚拟化
  • 原文地址:https://www.cnblogs.com/huanglexing/p/11560227.html
Copyright © 2011-2022 走看看