CS 160, Spring 2014
Programming Assignment P2
Numbers and Strings

Programming due Monday, Feb. 3 at noon; late deadline Feb. 3 at 10 p.m.


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 P2 project in Eclipse then write a class P2 with a main method, and put all of the following code into the main method:
  1. Declare an integer variable of type byte, short, int, and long.
  2. Declare a floating-point variable of type float, and double.
  3. Declare three variables of type char.
  4. Declare three instance variables of the class String.
  5. Initialize the variables using an initializer or assignment statement:
  6. byte: 97, short: 24567, int: 113355, long: 9384876238
  7. float: 1.57, double: 23.456
  8. char: '$', 'H', '3'
  9. String: "Java", "Programming", "Great"
  10. NOTE: The long integer value exceeds 32-bits, and therefore requires special syntax.
  11. NOTE: The float value similarly requires special syntax, otherwise it will default to type double.
  12. Find the syntax referenced above for long and float literals on the web and use them.
  13. (Line 1) Print the four integer values in the following order (byte,short,int,long) separated by commas.
  14. (Line 2) Print the two floating-point values in the following order (float, double) separated by colons.
  15. (Line 3) Print the sum of all the integer variables divided by 1000.
  16. (Line 4) Print the square root of the sum of all the floating-point variables.
  17. NOTE: You may use Math.sqrt() to compute the square root.
  18. (Line 5) Print the quotient of the double variable divided by the int.
  19. (Line 6) Print the three characters, separated by semicolons.
  20. (Line 7) Increment all three character values and print them again, separated by periods.
  21. (Line 8) Using the three String variables and string constants, print Java Programming is Great!.
  22. NOTE: The following items require a String method call inside a print statement.
  23. (Line 9) Print the length of all three String variables, separated by commas.
  24. (Line 10) Print the third String variable in uppercase letters.
  25. (Line 11) Print the third through sixth characters of the second String variable.
  26. (Line 12) Print the index of the character 'v' in the first String variable.
  27. (Line 13) Print the fourth character of the second 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.
97,24567,113355,9384876238
1.57:23.456
9385014
5.002599329593775
2.0692514666313793E-4
$;H;3
%.I.4
Java Programming is Great!
4,11,5
GREAT
ogra
2
g

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).

© 2014 CS160 Colorado State University. All Rights Reserved.