Question: 1. Base7 (15 points) Given an integer value X, you need to return the base-7 representation of X as a string. In a base-7

Given an integer value \( X \), you need to return the base-7 representation of \( X \) as a string. In a base-7 representati

ackage hk.edu.polyu. comp. comp2021. assignment1. base7; mport org.junit.Test; mport static org.junit.Assert.assertEquals; ubpackage hk.edu.polyu. comp. comp2021.assignment1.base7; public class Base7 \{ public static String convertToBase7(int num) \{   

1. Base7 (15 points) Given an integer value X, you need to return the base-7 representation of X as a string. In a base-7 representation, each digit is between 0 and 6, both inclusive, and the value of a digit is based on its position in the representation. For example, given a base-7 representation r = (dn...d3d2d1d0)7 (0 d; 6,0 in), the decimal value of r is calculated as d*7 + d3*73 + d2*7 + d*7 + do*7. What to do: In Base7.java [Task 1] Complete method convertToBase7 in class Base7 so that the method will take an int value as the argument and return the argument's String representation based on 7. For example, when the input value is 100, the method should return a string "202". Notes: You may not add new methods to class Base7. You may right-click on class Base7Test and select "Run 'Base7Test" to execute the tests we prepared for class Base7. If any test fails, your implementation is buggy. Note, however, that since the provided tests only check a small number of input/output pairs, passing all those tests does not mean your implementation is correct. package hk.edu.polyu.comp.comp2021.assignment1.base7; import org.junit.Test; import static org.junit.Assert.assertEquals; public class Base7Test { @Test(timeout = 2000) public void test1() { } assertEquals("202", Base7.convertToBase7(num: 100)); @Test(timeout = 2000) public void test2() { } assertEquals("10", Base7.convertToBase7 (num:7)); @Test(timeout = 2000) public void test3() { assertEquals("-24", Base7.convertToBase7 (-18)); } } package hk.edu.polyu.comp.comp2021.assignment1.base7; public class Base7 { public static String convertToBase7(int num) { // Todo: Add your code here return ""; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!