CS 570留学生程序 写作、java程序

” CS 570留学生程序 写作、java程序CS 570: Homework Assignment 11 Assignment PoliciesCollaboration Policy. Homework will be done individually: each student must hand in theirown answers. It is acceptable for students to collaborate in understanding the material but notin solving the problems or programming. Use of the Internet is allowed, but should not includesearching for existing solutions.Under absolutely no circumstances Code can be exchanged between students. Excerptsof code presented in class can be used.Your code must include a comment with your name.2 AssignmentDefine a class BinaryNumber That represents binary numbers and a few simple operations onthem, as indicated below. An example of a binary number is1011Its length is 4. Note that its leftmost digit is the least significant one: it represents the decimalnumber 120 +021 +122 +123 = 13. This is called little-endian format. You may use bigendianif you prefer; in that case you must state so at the beginning of your code as part of thecomment.This assignment requests that a number of operations be supported. They are divided intotwo groups. The first is a set of basic operations, the second is slightly more challenging andaddresses addition of binary numbers.2.1 Basic operationsThe following operations should be supported: A constructor BinaryNumber(int length) for creating a binary number of length length andconsisting only of zeros. A constructor BinaryNumber(String str) for creating a binary number given a string. Forexample, given the string 1011, the corresponding binary number should be created.For this exercise you will Have to use some standard String operations. These are listedin the Hints section below.CS 570留学生作业 写作、java程序语言 An operation int getLength() for determining the length of a binary number. An operation int getDigit(int index) for obtaining a digit of a binary number given an index.The starting index is 0. If the index is out of bounds, then a message should be printedon the screen indicating this fact. An operation int toDecimal() for transforming a binary number to its decimal notation (cf.the example given above). An operation void shiftR(int amount) for shifting all digits in a binary number any number ofplaces to the right, as indicated by a parameter amountToShift. The new digit should be0. For example, the result of shifting 1011 3 places to the right should yield 0001011.2.2 Addition of Binary NumbersHere is an example of how Two binary numbers of the same length are added1.1 1 1 1 (carried digits)1 0 1 1 0+ 1 1 1 0 0= 0 0 1 0 1 = 20Note that it is possible for the addition of two numbers to yield a result which has a largerlength than the summands. In that case, this should be flagged by an appropriate boolean datafield. Here is such an example.1 1 1 1 1 (carried digits)1 0 1 1 0+ 1 1 1 0 1= 0 0 1 0 0 1 = 36This data field should be Added to the data fields of the class BinaryNumber. Implement thefollowing operations: void add(BinaryNumber aBinaryNumber) for adding two binary numbers, one is the binarynumber that receives the message and the other is given as a parameter. If the lengths ofthe binary numbers do not coincide, then a message should be printed on the screenindicating this fact. Otherwise, it modifies the receiving binary number with the result ofthe addition. An operation clearOverflow() that clears the overflow flag.1 Source: httpss://en.Wikipedia.org/wiki/Binary_number3 An operation String toString() for transforming a binary number to a String. If the number isthe result of an overflow, the string Overflow should be returned.2.3 Hints For the BinaryNumber(String str) constructor, the following operations might come in handy: char java.lang.String.charAt(int index), which returns the char value at the specified index.An index ranges from 0 to length() – 1. The first char value of the sequence is atindex 0, the next at index 1, and so on, as for array indexing. int java.lang.Character.getNumericValue(char ch), which returns the int value that thespecified Unicode character represents. For the shiftR(int amount) operation, it might be useful to define an auxiliary private methodreallocate, that makes room for a new digit. This operation would in turn use int[]java.util.Arrays.copyOf(int[] original, int newLength), which copies the specified array, truncating orpadding with zeros (if necessary) so the copy has the specified length.3 Submission instructionsSubmit a single file named BinaryNumber.java through Canvas. No report is required. Yourgrade will be determined as follows: You will get 0 if your code does not compile. The code must implement the following UML diagram precisely. We will try to feed erroneous and inconsistent inputs to all methods. All argumentsshould be checked. Partial credit may be GIven for style, comments and readability.BinaryNumberprivate int data[] privateboolean overflowpublic BinaryNumber(int length)public BinaryNumber(String str)public int getLength() public intgetDigit(int index) public voidshiftR(int amount)public void add(BinaryNumber aBinaryNumber)public StringToString() public int toDecimal()public void clearOverflow()如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导