plastiq and ink preferred# Money - 海外理财
b*y
1 楼
我多年不用Java了,不太灵光了。对熟悉的牛们,应该不难。
Suppose that your boss walks in one day and drops the following code on your
desk. Your
asked to spend an hour or two and improve the quality of the code. What
would you suggest
to improve this? Each suggested improvement, comment, or observation can get
you extra
credit. If you have any questions, please make note of them as part of your
feedback!
Creativity is a plus.
Don't write any code! Just put your commentary inline, kind of a stream-of-
concisousness
approach.
class Person
{
public static Vector getPeople()
{
return people;
}
protected static Vector people = new Vector();
private String fName = "";
private String fAddress = "";
public Person (String name, String address)
{
if (name.length() == 0)
throw new IllegalArgumentException ("Person needs a non-blank name");
if (address.length() == 0)
throw new IllegalArgumentException ("Person needs a non-blank
address");
fName = name;
fAddress = address;
people.add (this);
initialize ();
}
protected void initialize ()
{
...;
}
public void store ()
{
try
{
String data = stringify ();
...;
}
catch (Exception e)
{
e.printStackTrace();
}
}
private String stringify ()
{
String result = "";
result += name;
// String[] items = address.split ("\s+", -2);
// for (int i = 0; i< items.length; i++)
// {
// result += "|";
// result += items[i];
// }
result += "|";
result += address;
return result;
}
}
class Customer extends Person
{
public static int BasicAcct = 0;
public static int PlusAcct = 1;
public static int ExecAcct = 2;
private long _accountid = 0;
private int _accounttype = 0;
public Customer (String name, String address)
{
super (name, address);
_accounttype = BasicAcct;
_accountid = IDManager.getId ();
}
protected void initialize ()
{
super.initialize ();
_accounttype = PlusAcct;
}
public void putAccountType (int acct)
{
_accounttype = acct;
}
public long getAccountId ()
{
return _accountid;
}
}
Suppose that your boss walks in one day and drops the following code on your
desk. Your
asked to spend an hour or two and improve the quality of the code. What
would you suggest
to improve this? Each suggested improvement, comment, or observation can get
you extra
credit. If you have any questions, please make note of them as part of your
feedback!
Creativity is a plus.
Don't write any code! Just put your commentary inline, kind of a stream-of-
concisousness
approach.
class Person
{
public static Vector getPeople()
{
return people;
}
protected static Vector people = new Vector();
private String fName = "";
private String fAddress = "";
public Person (String name, String address)
{
if (name.length() == 0)
throw new IllegalArgumentException ("Person needs a non-blank name");
if (address.length() == 0)
throw new IllegalArgumentException ("Person needs a non-blank
address");
fName = name;
fAddress = address;
people.add (this);
initialize ();
}
protected void initialize ()
{
...;
}
public void store ()
{
try
{
String data = stringify ();
...;
}
catch (Exception e)
{
e.printStackTrace();
}
}
private String stringify ()
{
String result = "";
result += name;
// String[] items = address.split ("\s+", -2);
// for (int i = 0; i< items.length; i++)
// {
// result += "|";
// result += items[i];
// }
result += "|";
result += address;
return result;
}
}
class Customer extends Person
{
public static int BasicAcct = 0;
public static int PlusAcct = 1;
public static int ExecAcct = 2;
private long _accountid = 0;
private int _accounttype = 0;
public Customer (String name, String address)
{
super (name, address);
_accounttype = BasicAcct;
_accountid = IDManager.getId ();
}
protected void initialize ()
{
super.initialize ();
_accounttype = PlusAcct;
}
public void putAccountType (int acct)
{
_accounttype = acct;
}
public long getAccountId ()
{
return _accountid;
}
}