b*******y 发帖数: 35 | 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;
}
} | l*****a 发帖数: 14598 | 2 什么厂啊?
your
get
your
【在 b*******y 的大作中提到】 : 我多年不用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.
| t**r 发帖数: 3428 | 3 问题太多了。呵呵。
一句话评语:shit code. fire the author and rewrite it |
|