CS 160, Summer 2016
Programming Assignment P1
Numbers and Strings

Programming due Thursday, June 16 at 6:00pm; late deadline at 11:59pm.


Using Numbers and Strings in Java

This programming assignment has four objectives:
  1. to use Java variables and operators to write expressions,
  2. to understand how to manipulate Java strings and characters,
  3. to print formatted output, and
  4. to see if you can follow a specification exactly!

Description

The program 1) declares a set of variables of several different data types, 2) uses the variables to construct expressions to do some simple math, 3) manipulates strings and characters, and 4) outputs the results.

Instructions

For this assignment, you must follow directions exactly. Create a P1 project in Eclipse then write a class P1 with a main method, and put all of the following code into the main method:
  1. Declare integer variables of type byte, short, int, and long.
  2. Declare floating-point variables of type float, and double.
  3. Declare three variables of type char.
  4. Declare three variables of the class String.
  5. Initialize the variables to the values shown below (using an initializer or assignment statement):
  6. byte: 19, short: 10203, int: 8796543, long: 4123456748L
  7. float: 3.1415f, double: 76.3434
  8. char: '^', 'W', '9'
  9. String: "Computer", "Science", "Delightful"
    NOTE: The long integer value exceeds 32-bits, and therefore requires special syntax.
    NOTE: The float value similarly requires special syntax, otherwise it will default to type double.
    NOTE: Find the syntax referenced above for long and float literals on the web and use them.
  10. (Line 1) Print the four integer values in the following order (byte,short,int,long) separated by commas (,).
  11. (Line 2) Print the two floating-point values in the following order (float, double) separated by a semicolons (;).
  12. (Line 3) Print the sum of all the integer variables divided by 9999.
  13. (Line 4) Use Math.sqrt() to compute and print the square root of the sum of the float and double.
    NOTE: Use System.out.printf with a specified to ensure exactly 3 digits after the decimal point.
  14. (Line 5) Print the quotient of the byte variable divided by the float variable.
    NOTE: Use System.out.printf with a specified to ensure exactly 5 digits after the decimal point.
  15. (Line 6) Print the three characters, separated by equals signs (=).
  16. (Line 7) Subtract 3 from all three character values and print them again, separated by tildes (~).
  17. (Line 8) Using the three String variables and string constants, print Computer Science is Delightful!.
    NOTE: The following items require a String method call inside a print statement.
  18. (Line 9) Print the length of all three String variables, separated by commas.
  19. (Line 10) Print the third String variable in uppercase letters.
  20. (Line 11) Print the second through seventh characters of the first String variable.
  21. (Line 12) Print the index of the character 'c' in the second String variable.
  22. (Line 13) Print the third character of the first String variable.

Sample output

Your program should match the output shown below, with no mispellings, wrong characters, incorrect case, or extra white space! A missing line will cause many errors, so make sure you have all of the lines below in the correct order. See the grading criteria below.
19,10203,8796543,4123456748
3.1415;76.3434
413267
8.915
6.04807
^=W=9
[~T~6
Computer Science is Delightful!
8,7,10
DELIGHTFUL
ompute
1
m

Specifications

Your program must meet the following specifications:

Grading Criteria

Submit your program to the Checkin tab on the course website, as you were shown in the recitation, and read the syllabus for the late policy (if necessary).

© 2016 CS160 Colorado State University. All Rights Reserved.