Weekly Plans and Assignments: 1. MONDAY(11/12): Finding the first derivative of an input algebraicfunction (Prog6_1), and Approximating the roots of the function by Newton's Method (Prog6_2). HW: Study Website Notes and Work on Programming Assignments not finished in class. 2. TUESDAY(11/13): Prog6_03 (Separate names, "Joe,Mary,Bill,Sam"), Prog6_04 (Reverse a string, "wow mom radar"), and Prog6_05 (Triangulate a string, "My Java Code"). HW: Study Website Notes and Work on Programming Assignments not finished in class. 3. WEDNESDAY(11/14): Prog6_06 (Separate a phone number, "5612415916", with hyphens), and Prog6_07 (Remove hyphens from SSNo, "163-25-6681"). HW: Study Website Notes and Work on Programming Assignments not finished in class. 4. THURSDAY(11/15): Prog6_08 (Count words in input string, "Are we having fun yet?"), and Prog6_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. FRIDAY(11/16): Prog6_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. 6. MONDAY(11/19): Prog6_11 (AI Dialog Project). HW: Study Website Notes and Work on Programming Assignments not finished in class. 7. TUESDAY(11/20): Finish the Prog6_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.6 -
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||