题目



代码
一
package ch09;
import java.util.Date;
public class Account { //Account类
public static void main(String[] args) {
Account account = new Account(1122, 20000);//初始化id和初始存款
account.setAnnualInterestRate(4.5);//输入年利率
account.withDraw(2500);//提取
account.deposit(3000);//存储
//打印余额,每月利息,以及该帐户创建的日期。
System.out.println("Balance: "+account.getBalance()+"\n"
+"Monthly Interest Rate: "+account.getMonthlyInterestRate()+"\n"
+"Date Created: "+account.getDateCreated());
}
private int id = 0;
private double balance = 0;
private double annualInterestRate = 0;
private Date dateCreated;
public Account() {
dateCreated = new Date();
}
public Account(int id, double balance) {
this.id = id;
this.balance = balance;
dateCreated = new Date();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public Date getDateCreated() {
return dateCreated;
}
public double getMonthlyInterestRate() {
double monthlyInterestRate = annualInterestRate / 12;
return balance * monthlyInterestRate / 100;
}
public void withDraw(double money) {
balance -= money;
}
public void deposit(double money) {
balance += money;
}
}
二
package ch09;
import java.util.Date;
import java.util.ArrayList;
public class b {
public static void main(String[] args) {
TestAcount ta = new TestAcount();
ta.main(args);
}
}
class TestAcount{
public static void main(String[] args) {
Acount a = new Acount();
long time = System.currentTimeMillis();
a.deposit('D', 30,time);//模拟存取款时的时间
a.deposit('D', 40,time + 100000000);
a.deposit('D', 50,time + 200000000);
a.withDraw('W', 5,time + 400000000);
a.withDraw('W', 4,time + 800000000);
a.withDraw('W', 3,time + 1600000000);
a.printJiLu();
System.out.println("账户创建日期为:"+a.getDateCreated());
}
}
class Acount{
private String name;
private int id;
protected double balance;
private double annualInterestRate;
private Date dateCreated;
private ArrayList jiaoyijilu = new ArrayList();
Acount(){
this("George",1122,1000,1.5);
}
Acount(String name,int id,double balance,double annualInterestRate){
this.name = name;
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
dateCreated = new Date();
}
public int getId(){
return id;
}
public void setId(int newID){
id = newID;
}
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 String getDateCreated(){
return dateCreated.toString();
}
public double getMonthlyInterestRate(){
return annualInterestRate / 12.0;
}
public void withDraw(char type,double amount,long elapstime){
Date date = new Date(elapstime);
Transaction actions = new Transaction(type,amount,balance,date);
jiaoyijilu.add(actions);
balance = actions.getNewBalance();
}
public void deposit(char type,double amount,long elapstime){
Date date = new Date(elapstime);
Transaction actions = new Transaction(type,amount,balance,date);
jiaoyijilu.add(actions);
balance = actions.getNewBalance();
}
public void printJiLu(){
System.out.println("名为:"+name+" ID: "+id+" 的账户交易记录如下:");
for(int i = 0;i < jiaoyijilu.size();i++){
System.out.println(jiaoyijilu.get(i).toString());
}
}
}
class Transaction extends Acount{
private char type;
private double amount;
private double newBalance;
private String description;
public Transaction(char type,double amount,double balance,Date date){
if(type == 'W'){
newBalance = balance;
newBalance -= amount;
description = date.toString()+" 取款 "+amount+" 可用余额为:"+newBalance;
}
else if(type == 'D'){
newBalance = balance;
newBalance += amount;
description = date.toString()+" 存款 "+amount+" 可用余额为:"+newBalance;
}
}
public double getNewBalance(){
return newBalance;
}
public String toString(){
return description;
}
}
三
package ch09;
import java.io.File;
import java.util.Scanner;
public class c {
public static void main(String[] args) {
try{
Scanner scanner=new Scanner(new File("11.txt"));
int [][] num = new int[20][20];
for (int i = 0; i < 17; i++) {
for (int j = 0; j < 20; j++) {
int n=scanner.nextInt();
//System.out.println(n);
num[i][j]=n;
}
}
//System.out.println(num);
int max = 0;
// 横向,从左到右
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 17; j++) {
int multi = 1;
for (int k = 0; k < 4; k++) {
multi *= num[i][j + k];
}
max = multi > max ? multi : max;
}
}
// 竖向,从上到下
for (int i = 0; i < 17; i++) {
for (int j = 0; j < 20; j++) {
int multi = 1;
for (int k = 0; k < 4; k++) {
multi *= num[i + k][j];
}
max = multi > max ? multi : max;
}
}
// 右对角线,从左下到右上
for (int i = 3; i < 20; i++) {
for (int j = 0; j < 17; j++) {
int multi = 1;
for (int k = 0; k < 4; k++) {
multi *= num[i - k][j + k];
}
max = multi > max ? multi : max;
}
}
// 左对角线,从左上到右下
for (int i = 0; i < 17; i++) {
for (int j = 0; j < 17; j++) {
int multi = 1;
for (int k = 0; k < 4; k++) {
multi *= num[i + k][j + k];
}
max = multi > max ? multi : max;
}
}
// 输出最大值
System.out.println(max);
}
catch (Exception e){
e.printStackTrace();
}
}
}
5701

被折叠的 条评论
为什么被折叠?



