COMP 110 Spring 2011
Assigned: Friday, January 28
Due: Friday, February 4 by 1:00pm
Lab 2 will introduce you to Java applets, string manipulation, and type casting. You have been given a skeleton program StringFun.java that can be found on the course webpage. Copy the program into Eclipse (You will need to create a new Java Project called lab2 and a new Java Class called StringFun), and compile and run the program. (Don't forget to add the header!)
Characters are stored as numbers in a computer. This java applet converts the input integer to the unique Unicode character stored as that number. Appendix 7 has a subset of the Unicode character set. Note: the input integer was type cast as a character.
Type casting is more commonly done between integers and floating-point numbers. Often when performing arithmetic operations between the two types.
- Comment out the first JOption line and uncomment the second JOption line. Recompile and run the program.
- The second display box should now say Rocks!
- Add your favorite band's name to the dialog box by type casting Unicode characters. Start the name of your band after the "". Use Appendix 7 for a reference. (choose a band that has more that 5 characters in the name.)
For this part of the lab you will modify the code StringFun.java to prompt the user for a string (of characters) and output information about the string as well as manipulate the input string.You will be referencing pages 75-80 of your textbook.
- Declare a variable of Type String to be your input string with identifier inputString.
- Prompt the user to input a string.
inputString = JOptionPane.showInputDialog("Please Enter a string:");
This line of code will prompt the user and store the input string in inputString
- Manipulate the string stored in inputString - reference pages 75-80. For each step, print out a new dialog box using
JOptionPane.showMessageDialog(null, your output goes here);
- Output the length of inputString
- Convert inputString to all uppercase letters
- Print out the characters at positions 0 and 5 (assume the user input a string with more than 6 characters)
- Display the substring starting at position 0 and ending at position 5
- Display the inputString without the first word. (Hint: find the index of the first space in the string. Then display the substring starting at the next index past the first space)
Additional Questions (in project lab2 in Eclipse, create a new File called yourlastname_lab2.txt and answer questions in the file)
What was the most helpful part of this lab? least helpful?
Has any part of lecture been confusing that you would like covered again? What?
- Modular Arithmetic (Solve these problems, Remember you are calculating the remainder)
- 5 points Part 1
- 15 point Part 2
- 3 points Declaring variables and display prompt
- 12 points String Manipulation
- 3 points Additional Questions
- 2 points Handing in the assignment correctly on the first try
How to hand in the assignment
- A file named yourlastname_lab2.txt, where yourlastname
is your last name, that provides answers to the Additional Questions.
Make sure the file has the appropriate header.
A file named yourlastname_lab2.jar, where yourlastname is your last name.
The .jar file should include StringFun.java, StringFun.class, MANIFEST.MF (under META-INF folder), and yourlastname_lab2.txt.
Your java file should have the appropriate header.
Follow these instruction to create yourlastname_lab2.jar.
Submit on Blackboard via Digital Dropbox (Send File) yourlastname_lab2.jar by 1:00 Friday February 4.
If you do not follow these instructions you will not get credit for the lab. Please let
me know if you are having any problems with the assignment submission process.