Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me write my code in java. Only the method public static int byteCount ( int codePoint ) and public static byte [ ]
Please help me write my code in java. Only the method public static int byteCountint codePoint and public static byte toBytesint codePoint need to be implemeted. Methods testByteCount and testToBytes should run true with the code provided. Thank you! and please add comments to help guide me through the code
import java.util.Arrays;
public class UTF
public static void mainString args
System.out.printlntestByteCountfalse;
System.out.printlntestToBytesfalse;
Returns the number of bytes that are used
to encode a code point when using UTF
@param codePoint
@return the number of bytes that encode codePoint in UTF
public static int byteCountint codePoint
if codePoint
return ;
Four cases which return and respectively...
return ; For large code points which cannot be encoded.
Returns the bytes that are used
to encode a code point when using UTF
@param codePoint the code point to encode
@return the bytes that encode codePoint in UTF
public static byte toBytesint codePoint
int count byteCountcodePoint;
byte b new bytecount;
Four cases...
return b;
Provided that byteCount is defined correctly,
this method should return true.
@param print whether to print the testing chars in the console
@return true
private static boolean testByteCountboolean print
boolean bool true;
int codePoints new int
xyu~
;
for int i ; i ; i
for int j ; j ; j
bool &byteCountcodePointsi ji ;
if print
for int codePoint : codePoints
System.out.printCharactertoCharscodePoint;
System.out.println;
return bool;
Provided that toBytes is defined correctly,
this method should return true.
@param print whether to print the testing chars in the console
@return true
private static boolean testToBytesboolean print
boolean bool true;
int codePoints new int
xyu~
;
byte bytes new byte
;
bool & Arrays.equalstoBytescodePoints new byte bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes bytes bytes;
bool & Arrays.equalstoBytescodePoints new byte bytes bytes bytes bytes;
if print
for int codePoint : codePoints
System.out.printCharactertoCharscodePoint;
System.out.println;
return bool;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started