有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

爪哇巴比伦数字表示法

我是java新手,在接下来的两周内将完成以下任务。任何关于如何开始的建议都将不胜感激:

Write a Java class whose instances represent Babylonian numbers. Your class should provide at least the following methods:

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

If there are restrictions on the magnitude of the numbers that can be represented by your class, say what those restrictions are.


共 (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)
      {
      }
    }