java 第十二周

在这里插入图片描述
在这里插入图片描述

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

class Account{
    private int id = 0;   //账户名
    private double balance = 0;   //余额
    static private double annualInterestRate = 0;      //年利率
    private java.util.Date dateCreate = new java.util.Date();  //开户日期
    Account(){  //创建默认账户
        dateCreate = new Date();
    }

    Account(int ID,double Balances){  //创建指定用户和初始余额
        id = ID;
        balance = Balances;
        dateCreate = new Date();
    }

    public int getID(){  //访问 ID
        return id;
    }

    public void setID(int name){  //修改 ID
        id = name;
    }

    public double getBalance(){  //访问 余额
        return balance;
    }

    public void setBalance(double newbalance){  //修改 余额
        balance =  newbalance;
    }

    public double getAnnualInterestRate(){   //访问 年利率
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double newrate){   //修改 年利率
        annualInterestRate = newrate;
    }

    public java.util.Date getDateCreate(){  //访问 开户日期
        return dateCreate;
    }

    public double getMonthlyInterestRate(){  //返回月利率;
        return annualInterestRate / 12;
    }

    public double getMonthlyInterest(){  //返回月利息
        return balance * getMonthlyInterestRate();
    }

    public void withDraw(double drawMoney){  //取款
        if (balance >= drawMoney)
            balance = balance - drawMoney;
    }

    public void deposit(double saveMoney){  //存款
        balance = balance + saveMoney;
    }
}

public class Hello extends Account{
    private String name; //客户名
    private ArrayList<Transaction> transactions;  //存储交易明细
    public Hello(String Name,int ID,double Balances){  //创建具有指定名字,id和余额的账户
        name = Name;
        setID(ID);
        setBalance(Balances);
        this.transactions = new ArrayList<Transaction>();
    }
    public void Draw(double Money){   //取款
        withDraw(Money);
        transactions.add( new Transaction('W',Money,getBalance(),"交易成功"));
    }
    public void Deposit(double Money){  //存款
        deposit(Money);
        transactions.add( new Transaction('D',Money,getBalance(),"交易成功"));
    }
    public String getName(){  //访问 客户名
        return name;
    }
    public void setName(String Name){  //修改 客户名
        name = Name;
    }
    public static void main(String[] args) {
//
//        Account account = new Account(1122,20000.0);
//        account.setAnnualInterestRate(4.5/100);
//        account.withDraw(2500.0);
//        account.deposit(3000.0);
//        System.out.println(" 月利息:" + account.getBalance() * account.getAnnualInterestRate()/12 + " 当前余额:"
//                            + account.getBalance() + "美元, 开户日期:"+ account.getDateCreate());



        Hello account = new Hello("George",1122,1000.0);
        account.setAnnualInterestRate(1.5/100);
        account.Deposit(30.0);
        account.Deposit(40.0);
        account.Deposit(50.0);
        account.Draw(5.0);
        account.Draw(4.0);
        account.Draw(2.0);
        System.out.println("客户名:" + account.getName() + " 年利率:" + account.getAnnualInterestRate() + " 当前余额:" + account.getBalance() + "美元");
        System.out.print(account.transactions.toString());

    }
}

class Transaction{
    private Date date;  //该交易的日期
    private char type;  //交易类型,如“W”代表取款,“D”代表存款
    private double amount;  //交易量
    private double balance; //交易后新的余额
    private String description;  //交易描述
    Transaction(char Type,double Amount,double Balance,String Description){
        type = Type;
        amount = Amount;
        balance = Balance;
        description = Description;
        date = new Date();
    }
    public Date getDate(){  //访问 交易日期
        return date;
    }
    public char getType(){  //访问 交易类型
        return type;
    }
    public double getAmount(){  //访问 交易量
        return amount;
    }
    public double getBalance(){  //访问 交易后余额
        return balance;
    }
    @Override
    public String toString(){
        return "交易记录:" + new SimpleDateFormat("yyyy-MM-dd").format(date) + " " + type + " " + amount + " " + balance + " 美元 " + description + "\n";
    }
}


在这里插入图片描述

/**
 * Created by SiceLab on 2021/5/17.
 */


public class FindBigNum {
    public static void main(String[] args) {
        int arr[][] = {{8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8},
                {49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,4,56,62,0},
                {81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,3,49,13,36,65},
                {52,70,95,23,4,60,11,42,69,24,68,56,1,32,56,71,37,2,36,91},
                {22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80},
                {24,47,32,60,99,3,45,2,44,75,33,53,78,36,84,20,35,17,12,50},
                {32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70},
                {67,26,20,68,02,62,12,20,95,63,94,39,63,8,40,91,66,49,94,21},
                {24,55,58,5,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72},
                {21,36,23,9,75,0,76,44,20,45,35,14,0,61,33,97,34,31,33,95},
                {78,17,53,28,22,75,31,67,15,94,3,80,4,62,16,14,9,53,56,92},
                {16,39,5,42,96,35,31,47,55,58,88,24,0,17,54,24,36,29,85,57},
                {86,56,0,48,35,71,89,7,5,44,44,37,44,60,21,58,51,54,17,58},
                {19,80,81,68,5,94,47,69,28,73,92,13,86,52,17,77,4,89,55,40},
                {4,52,8,83,97,35,99,16,7,97,57,32,16,26,26,79,33,27,98,66},
                {88,36,68,87,57,62,20,72,3,46,33,67,46,55,12,32,63,93,53,69},
                {4,42,16,73,38,25,39,11,24,94,72,18,8,46,29,32,40,62,76,36},
                {20,69,36,41,72,30,23,88,34,62,99,69,82,67,59,85,74,4,36,16},
                {20,73,35,29,78,31,90,1,74,31,49,71,48,86,81,16,23,57,5,54},
                {1,70,54,71,83,51,54,69,16,92,33,48,61,43,52,1,89,19,67,48},
        };
        System.out.println((FourMax(Left2Right(arr), Up2Down(arr), LeftU2RightD(arr), LeftD2RightU(arr))));
    }

    private static long FourMax(long a, long b, long c, long d) {
        long max = a;
        if(b > max)
            max = b;
        if(c > max)
            max = c;
        if(d > max)
            max = d;
        return max;
    }

    public static long Left2Right(int arr[][]){
        int max = 0;
        int value = 0;
        for (int i = 0; i < 20; i++){
            for(int j = 0; j < 17; j++){
                value = arr[i][j] * arr[i][j+1] * arr[i][j+2] * arr[i][j+3];
                if (value >= max)
                    max = value;
            }
        }
        return max;
    }

    public static long Up2Down(int arr[][]){
        int max = 0;
        int value = 0;
        for(int i = 0; i < 17; i++){
            for(int j = 0; j < 20; j++){
                value = arr[i][j] * arr[i+1][j] * arr[i+2][j] * arr[i+3][j];
                if (value >= max)
                    max = value;
            }
        }
        return max;
    }

    public static long LeftU2RightD(int arr[][]){
        int max = 0;
        int value = 0;
        for(int i = 0; i < 17; i++){
            for(int j = 0; j < 17; j++){
                value = arr[i][j] * arr[i+1][j+1] * arr[i+2][j+2] * arr[i+3][j+3];
                if (value >= max)
                    max = value;
            }
        }
        return max;
    }

    public static long LeftD2RightU(int arr[][]){
        int max = 0;
        int value = 0;
        for(int i = 3; i < 20; i++){
            for(int j = 0; j < 17; j++){
                value = arr[i][j] * arr[i-1][j+1] * arr[i-2][j+2] * arr[i-3][j+3];
                if(value >= max)
                    max = value;
            }
        }
        return max;
    }
}

// 更好的方法应该是在20*20的矩阵外围增加宽边,26*26的矩阵
// 并且将26*26的矩阵初始化为1
// 这样在for循环不需要考虑越界问题,可以全量遍历
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值