我正在银行写一个java项目。 主类调用另一个名为Account的类。 我有10个帐户,所以我必须制作10个对象。
是否可以制作此类对象的数组?如果是这样怎么样?。
以下是Account类代码的代码:
import java.util.*;
import java.io.*;
class Account
{
private String Name;
private int age;
private long accnum;
private int pin;
private int phone;
private boolean gender;
private double balance;
private double interest;
private int lastpin;
public Account(String nm,int ag,long acc,int phon,boolean gen,double bal,int last)
{
Name = nm;
age = ag;
accnum = acc;
phone = phon;
gender = gen;
balance = bal;
lastpin = last;
pin = Random(lastpin);
}
public int Random(int num)
{
int count = 0;
num = num * 1103;
int num1=num;
int divide = 1;
test:
while(true){
while(num != 0)
{
num =(int)(num/10);
//num /= 10;
++count;
}
if(count > 4)
divide =(int)(Math.pow(10,(count - (count - 3))));
else if(count < 4)
{
num1 = num1 * 11;
continue test;
}
break test;
}
lastpin = (num1/divide);
return (num1/divide);
}
public void Deposit(double amount)
{
balance = balance + amount;
}
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*public String[] Initnm(String x[]){
for(int i = 0,j = 0;i < x.length || j < x.length;i++,j++){
char ch = (char)j;
x[i] = Character.toString(ch);;
}
return x;
}*/
//sha
private long[] Initacc(long x[]){
for(long i = 0;i < x.length ; i++){
if(((int) Math.log10(i) + 1) == 1)
x[(int)i] = Long.parseLong("10105175407".concat("00".concat(Long.toString(i))));
else if(((int) Math.log10(i) + 1) == 2)
x[(int)i] = Long.parseLong("10105175407".concat("0".concat(Long.toString(i))));
else if(((int) Math.log10(i) + 1) == 3)
x[(int)i] = Long.parseLong("10105175407".concat(Long.toString(i)));
}
return x;
}
private int[][] InitAgenda(int[][]x)
{
for(int i = 0;i < x.length;i++)
{
x[0][i] = 100;
x[1][i] = 0;
}
return x;
}
private int[] Initpin(int x[]){
for(int i = 0,j = 1000;i < x.length;i++,j++){
x[i] = j;
}
return x;
}
private double[] Initbal(double x[]){
for(int i = 0;i < x.length;i++){
x[i] = 200.00d;
}
return x;
}
private double[] Initirst(double x[],char ch){
for(int i = 0;i < x.length;i++){
if(ch == 's')
x[i] = 3.10d ;
else if(ch == 'c')
x[i] = 0.0d;
}
return x;
}
}
这是处理所有帐户的Account类。 主要课程太长而无法展示。 谢谢大家。
答案 0 :(得分:0)
是的,您可以创建一个这样的对象数组: 首先使你想要制作
对象的类class MyClass {
}
制作一个类型为“MyClass”的对象数组,大小为n
int n = 10;
MyClass[] myClassArray = new MyClass[n];
对于你的班级,该行将是:
Account[] accounts = new Account[10];