Assignment 2 Base Conversion PDF

Title Assignment 2 Base Conversion
Course Introduction to Computing Using Java
Institution 香港中文大學
Pages 3
File Size 64.8 KB
File Type PDF
Total Downloads 10
Total Views 151

Summary

Download Assignment 2 Base Conversion PDF


Description

CSCI 1130A/B Introduction to Computing Using Java 2018-2019 First Term Department of Computer Science and Engineering The Chinese University of Hong Kong

Assignment 2: Number Base Conversion Due date: 10 October 2018 (Wed)

Full mark: 100 Expected normal time spent: 6 hours

Aims: 1. To solve the number base conversion problem by writing a Java program. 2. Practice using variables, expression and looping/branching statements.

Background: The most common number system that we use every day is the decimal number system, which is also known as the base 10 system. In a decimal system, there are 10 different symbols. The value of a number can be computed by multiplying each digit with the corresponding positional weight. For example: A decimal number sequence: 12345610 = 1*10 5 + 2*10 4 + 3*103 + 4*10 2 + 5*10 1 + 6*10 0 In this assignment, we are going to deal with numbers in base 5 and base 7. In general, one may use the following formula to convert a base N10 number to base 10 (N itself is represented in base 10): abcdefN = a*N 5 + b*N4 + c*N 3 + d*N2 + e*N1 + f*N0 where a, b, c, d, e and f are digits in [0, N-1] For example, for N = 5, then 1234035 = 1*55 + 2*5 4 + 3*5 3 + 4*5 2 + 0*5 1 + 3*50 = 4853 10 The above method is to convert a base N number to base 10. To reverse the process, another algorithm, known as repeated division, is required. For example, we can change a base 10 number, say 2310, to base 5 by 5|23 … 3 5|4 … 4 We take the remainders from bottom to top. The answer is 435. To change a base 10 number to any other bases, say N, we are required to perform a similar procedure by replace 5 with N. In our assignment, N can only be 5 or 7.

1

Problem Definition: In this assignment, you are required to write a program to perform number conversion among base 5, 7 and 10 numbers. You are required to obtain the input number from the console standard input using Scanner and System.in. A sample run of the program is shown below: Enter a base 10 number: 123456 The number in base 5 and 7 are: 12422311, 1022634 Enter a base 5 number: 123403 The number in base 7 and 10 are: 20102, 4853 Enter a base 7 number: 123456 The number in base 5 and 10 are: 1213000, 22875 There are at most six digits in the any of the input numbers. You are NOT required to validate the input numbers. It means that you can assume all input numbers are valid. In the conversion process, you are NOT allowed to use any elements/methods related to the class String. You shall define one package exercise and one class called BaseConversion in a new NetBeans project named BaseConversion. The class shall contain a main method that performs all the operations including input, conversion and output. Optionally, you may define more than one method in addition to the main method to carry out the conversion. Procedure: 1. Create a new NetBeans project with a source file named BaseConversion.java that contains the class BaseConversion, under package exercise. 2. Define the main method, together with optionally other fields and methods (if any), to perform I/O as well as base conversion in the BaseConversion class. 3. If you have completed writing the BaseConversion class, try build the project (press the function key [F11] on the keyboard). If there are errors, don’t panic. Double-click on the first error message in the Output window. Check the error, correct it and re-compile. Feel tired? Take a rest. 4. If you have many opened projects, close others or click menu [Run] [Set Main Project]. 5. You may insert println() statements in your work to inspect variables and intermediate results. 6. When you finish and there is no more error, you are ready to try out the program by pressing the function key [F6] on the keyboard. Then you can type the input number in the standard input. Enjoy your work.

2

Submission: 1. Locate your NetBeans project folder, e.g. H:\BaseConversion\. 2. ZIP the project folder BaseConversion and Submit the file BaseConversion.zip via our Online Assignment Collection Box on Blackboard https://blackboard.cuhk.edu.hk Marking Scheme and Notes: 1. The submitted program should be free of any typing mistakes, compilation errors and warnings. 2. Comment/remark, indentation, style is under assessment in every programming assignments unless specified otherwise. Variable naming, proper indentation for code blocks and adequate comments are important. Insert your name, SID, section, date as well as a declaration statement on academic honesty in a header comment block in the source file. 3. Test your work using different sets of inputs. 4. Remember to do your submission before 6:00 p.m. of the due date. No late submission would be accepted. 5. If you submit multiple times, ONLY the content and time-stamp of the latest one would be counted. You may delete (i.e. take back) your attached file and re-submit. We ONLY take into account the last submission.

University Guideline for Plagiarism: Attention is drawn to University policy and regulations on honesty in academic work, and to the disciplinary guidelines and procedures applicable to breaches of such policy and regulations. Details may be found at http://www.cuhk.edu.hk/policy/academichonesty/. With each assignment, students are required to submit a statement that they are aware of these policies, regulations, guidelines and procedures, in a header comment block.

Faculty of Engineering Guidelines to Academic Honesty: MUST read: https://www.erg.cuhk.edu.hk/erg/AcademicHonesty (you may need to access via CUHK campus network/ CUHK1x/ CUHK VPN)

3...


Similar Free PDFs