CS1150 (Spring 2013): Programming Assignment 1

Variables and Expressions


Instructions

  1. Install DrJava from this link. Download the latest stable version and place the file that downloads in a safe place. This file is not an installer; it is the actual program. This makes it very portable and means that if you store it on e.g. a flash drive, you can run it from any computer.
  2. Run DrJava by double-clicking on the program and type the following code into the editor window:
    /* Operations.java
     * Your name
     * CS1150.1301, Programming Assignment #1
     * Get a string, then use it and some other values to perform
     * various computations.
     */
    import java.util.Scanner;
    
    public class Operations {
      public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
    
        // Your code will go here
      }
    }
    
  3. Save the file as Operations.java and compile and run the program (it doesn't do a whole lot).
  4. Add code to enable the following conversation, storing the inputs (in bold) in variables of appropriate types and performing the appropriate calculations to make the output make sense. Test with a variety of different inputs:
    Enter a word or phrase: Why hello, there
    You entered "Why hello, there"
    The string is 16 characters long
    Enter an integer to divide by: 5
    Integer division: 3
    Floating point division: 3.2
    Enter a floating point number to add: 3.14
    Result: 6.14 6.34
    

Deliverables

Submit the source code file (Operations.java) and the output of your testing.