Weekly Plans and Assignments: 1. Wednesday(10/07): Encrypting a statement (Prog4_1), and Decryptinga statement (Prog4_2). HW: Study Website Notes and Work on Programming Assignments not finished in class. 2. Thursday(10/08): Prog4_03 (Separate names, "Joe,Mary,Bill,Sam"), Prog4_04 (Reverse a string, "wow mom radar"), and Prog4_05 (Triangulate a string, "My Java Code"). HW: Study Website Notes and Work on Programming Assignments not finished in class. 3. Friday(10/09): Prog4_06 (Separate a phone number, "5612415916", with hyphens), and Prog4_07 (Remove hyphens from SSNo, "163-25-6681"). HW: Study Website Notes and Work on Programming Assignments not finished in class. 4. Monday(10/12): Prog4_08 (Count words in input string, "Are we having fun yet?"), and Prog4_09 (Scan an input string, "What is your name?", look for "name", if found, respond with "My name is Tobor."). HW: Study Website Notes and Work on Programming Assignments not finished in class. 5. Tuesday(10/13): Prog4_10 (Scan an input string, "How are you? I hope you are doing well.", look for "How are you", if found, respond with random "I am (a) "fine.", (b)"happy.", or (c) "sad."). HW: Study Website Notes and Work on Programming Assignments not finished in class. Try the 8-Queens Problem. 6. Wednesday(10/14): Prog4_11 (AI Dialog Project). HW: Study Website Notes and Work on Programming Assignments not finished in class. 7. Thursday(10/15): Finish the Prog4_11 (AI Dialog Project). HW: Study Website Notes and Work on Programming Assignments not finished in class. Very Important: If you have any questions or were absent from class, see me before school (8:00 - 8:30 AM), during Lunch, 7th hour, or after school. Best to send an email to rpersin@fau.edu.
Website Notes: Ch.4 -
The Java Char and String Classes. 1. Character
class static methods. // This program reads a single character from
the keyboard and displays it If a non-String object is part of the
concatenation, its string representation is produced by calling its
toString() method. When you write a class that might have a
sensible representation as a string, it's often useful for debugging
purposes to define a toString() method. If no such method is
defined, the default version from Object is used. //Here is the standard way of getting text. public class Echo3 { Below are some of the most common String methods that
we will be using. In all of these prototypes,
Strings, and
4. Convert from type X to type Y integer to String : int i = 42; String str = Integer.toString(i); or String str = "" + i double to String : String str = Double.toString(i); long to String : String str = Long.toString(l); float to String : String str = Float.toString(f); String to integer : str = "25"; int i = Integer.valueOf(str).intValue(); or int i = Integer.parseInt(str); String to double : double d = Double.valueOf(str).doubleValue(); String to long : long l = Long.valueOf(str).longValue(); or long l = Long.parseLong(str); String to float : float f = Float.valueOf(str).floatValue(); decimal to binary : int i = 42; String binstr = Integer.toBinaryString(i); decimal to hexadecimal : int i = 42; String hexstr = Integer.toString(i, 16); or String hexstr = Integer.toHexString(i); hexadecimal (String) to integer : int i = Integer.valueOf("B8DA3", 16).intValue(); or int i = Integer.parseInt("B8DA3", 16); ASCII code to String : int i = 64; String aChar = new Character((char)i).toString(); integer to ASCII code (byte) : char c = 'A'; int i = (int) c; // i will have the value 65 decimal To extract Ascii codes from a String : String test = "ABCD"; for ( int i = 0; i < test.length(); ++i ) { char c = test.charAt( i ); int i = (int) c; System.out.println(i); } integer to boolean : b = (i != 0); boolean to integer : i = (b)?1:0;
5. Here is an idea for a String Program:
public class How4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|