-2

我是 Java 新手,并已收到以下任务,需要在接下来的 2 周内完成。任何有关如何开始的指针将不胜感激:

编写一个 Java 类,其实例代表巴比伦数字。您的课程至少应提供以下方法:

  1. 一个以巴比伦形式表示的数字作为输入的构造函数(String例如"34,45,2"or"1,23,4,59,55"等​​)
  2. 一种将当前巴比伦数字的值作为整数返回的方法;
  3. 一种将巴比伦数字转换为字符串形式的方法;
  4. 一种将两个巴比伦数字相加以产生新巴比伦数字的方法;
  5. 一种从当前巴比伦数中减去传递的巴比伦数以产生新巴比伦数的方法;

如果您的班级可以表示的数字的大小受到限制,请说出这些限制是什么。

4

1 回答 1

1

您将在下面找到一组可能对您有所帮助的方法:

/**
 * A representation of a Babylonina number.
 * <p>
 * TODO some examples/explanations of what Babyloninan numbers
 */
class Babylonian
{
  /**
   * Constructs a Babylonina number from a string.
   */
  public Babylonian(String number)
  {
  }

  /**
   * Returns the value of this Babyloninan number as an {@code int}.
   *
   * @return the value of this Babylonian number (as an int)
   */
  public int getBabylonian()
  {
  }

  /**
   * Returns the value of this Babyloninan number as a {@code String}.
   *
   * @return the value of this Babylonian number (as a String)
   */
  public String toString()
  {
  }

  /**
   * Adds the Babylonian number {@code x} to this number.
   *
   * @param x the Babylonian number to add
   */
  public void add(Babylonian x)
  {
  }

  /**
   * Substracts the Babylonian number {@code x} to this number.
   *
   * @param x the Babylonian number to substract
   */
  public void subtract(Babylonian x)
  {
  }
}
于 2013-03-29T14:59:31.763 回答