HW1 Assignment

What to do?

This assignment needs to be turned in on or before Wednesday, September 29th, 2021 at 11:59 AM (NOON, NOT MIDNIGHT). In addition to turning in by the deadline, to ensure full credit, this assignment may be checked off by a tutor. Assignments turned in by the deadline and not checked off by a tutor will be evaluated through the normal autograding process.
Start early! There are many students but only a limited amount of tutors avaliable to check off at any given time. No submissions after the deadline will be accepted.

You will be writing a program in Java. You will be required to write methods which display output to the user. The methods to implement in the hw1.java file are:

void baseout (long number, long base, PrintStream stream);
void decout (long number, PrintStream stream);
void newline (PrintStream stream);
long writeline (String message, PrintStream stream);

Method Descriptions

baseout:

The baseout method takes the long integer number provided by the user, converts it to the base that is passed in, and displays it to the filestream stream. This requires separating the number into individual characters, converting each character into its digit value, and then displaying the result. The algorithm will be explained fully in class. The key to writing this method is knowing that modding a number by its base will return one digit, and dividing a number by its base will remove that digit. You may want to use a loop. For this method, you will want to use fputc.

  • Values of number are expected to be any positive integer.
  • Values of base are expected to be any positive integer between 2 and 36.
  • Values of stream are expected to be either System.out and System.err in hw1.java.
  • decout:

    The decout method takes the long integer number provided by the user and displays it to the filestream stream as an integer. This requires separating the number into individual characters, converting each character into its digit value, and then displaying the result. This should be implemented by delegating to baseout.

  • Values of number are expected to be any positive integer.
  • Values of stream are expected to be either System.out and System.err in hw1.java .
  • newline:

    Displays a newline character ('\n') to the filestream stream. You'll want to use fputc. This method shouldn't take more than a single line of code to implement.

  • Values of stream are expected to be either System.out and System.err in hw1.java.
  • writeline:

    Displays the string message to the user via the filestream stream. This method should be implemented using a loop making calls to fputc. This function should return the number of characters printed.

    Implementation Restrictions

    To implement these methods, you may not make calls to ANY methods you did not author except for fputc. You may call on the String methods charAt and length for hw1.java. fputc takes one character and prints it to a provided stream, but it is not built-in in Java. However, it has been implemented for you in hw1.java. If you don't remember how charAt or length works, here is a link to the API: API for String class

    Grading breakdown

    Ask a tutor to check your homework when you are done. The tutor will only check off each component below once it is complete. If a component is not complete when you ask for checkoff, you can complete what is missing and ask for checkoff again. Failure to get checked off may cost you points in future homeworks as this is the fastest way to correct any misunderstandings and oversights you may have.

    writeline:
    10 pts
    decout/baseout:
    10 pts
    style/documentation:
    5pt deduction each if absent

    How to get started?

    Copy and paste the following commands into your terminal.

    cd
    cd ../public/hw1
    make install
    cd
    cd hw1/java
    mv hw1.java.empty hw1.java
    ls