Class Notes (806,973)
Canada (492,546)
ITM 200 (22)
Vikirmin (5)

Chap 4 ITM 200.docx

4 Pages
Unlock Document

Ryerson University
Information Technology Management
ITM 200

yhuJOptionPane.showMessageDialog()  method of JOptionPane(class). It has a textbox in which the user may type in a string (input). Example: String test=JOptionPane.showInputDialog(“Enter your first integer”); A input box will appear on the screen asking you to Enter your first integer. Suspose you type 42 into the text field, when the user presses the OK button, the showInputDialog method will return with a string of “42”. If you do another input integer of 24 with test2 string, you will have 42 and 24. You must convert these string variables into integers in order to do calculations. Therefore, use parse. Integers: parseInt() Doubles: parseDouble() Characters: charAt() *Note: for charAt(), the position starts at 0. It is required to find the character at a specific position in a particular string* Example: String s=”Hello”; s.charAt(0); is H s.charAt(1); is E s.charAt(2); is L Declare a integer variable (mytest) so you can store the int equilvaent of the String (test1) in the variable: Int mytest= Integer.parseint(test1); Primitive Type Variables: float numbers, chars, doubles, and integers = literal values Reference Types: does not actually contain its associated data but contains a reference to the data (the address of the location where the data is stored in the computer’s memory) = string variables Objects: can contain more than one piece of data (so it is possible to over write strings and leave one string with no value which will eventually be collected by the garbage collector) Strings are a class, and objects are the reference variables String Comparisons +equals(s1:String) boolean = returns true if this string is equal to string s1 Example: String s1= new String("Welcome"); String s2= "Welcome"; 1) if (s1.equals(s2)) //s1 and s2 have the same contents 2) if (s1 == s2) //s1 and s2 have the same reference+equalsIgnoreCase(s1:String) boolean =returns true if this string is equal to string s1 case insensitive +compareTo(s1:String) integer = returns an integer greater than 0, equal to 0, or less than 0 to indicate whether this string is greater than, equal to, or less than s1 Example: String s1 = new String("Welcome“); String s2 = “You are welcome"; if (s1.compareTo(s2)> 0) { // s1 is greater than s2 else if (s1.compareTo(s2) == 0) { // s1 and s2 have the same contents } else // s1 is less than s2 +compareToIgnoreCase(s1:String) integer: sames as compareTo except that the comparison is case insensitive +regionMatches(toffset:int, s1 string, offset: int len int) boolean: returns true if the specified subregion of this string exactly matches the specified subregion in string s1 +regionMatches(ignoreCase:boolean, toffset: int, s1 string, offset int, len int) boolean: same as the preceding method except that you can specify whether the match is case sensitive +startsWith(prefix: String) boolean: returns true if this string starts with the specified prefix String length: length() = int Example: Message=”Welcome”; Message.length(); =returns 7 +endsWith(suffix: S
More Less

Related notes for ITM 200

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.