Docsity

IT108 Class Notes: API Documentations and User Input Validation - Prof. Irene Bruno, Study notes of Information Technology

Toggle sidebar
bg1
IT108
April 30, 2009
On Blackboard
Two new links
oWhat the final is going to be link
oQuestions from past exams (she did not use any of them this
year)
Tuesday
Anything you want to do Tuesday we will do
I will stare at you until you ask me questions
Phase Two Information
User should be able to choose
API documentations
oChar class
oString class
Don’t have to include all the crap
Just need to include name, data types, etc.
You need to know which methods to play around with before the Final
Background information
oThese are the common ones
oOnce you get use to them you will be able to use them
oThe last sheet of the final provided will be API stuff that you don’t
need to include on your cheat sheet
The two methods
oDifferences between Character and String
Char
Does not deal with instance variable
Str
Does stuff with instance variable
oCharacter
Provides us to have methods
Methods Bruno is interested in
isDigit
isSpace
isLetterOrDigit
IsLetter
isUpperCase
isLowerCase
oString
Method types
charAt
equals
equalgnoreCase All instance! All of
them! Notice the lack of
static. Does stuff with
instance variable.
All static! All of
them!
pf3
pf4
pf5

Partial preview of the text

Download IT108 Class Notes: API Documentations and User Input Validation - Prof. Irene Bruno and more Study notes Information Technology in PDF only on Docsity!

April 30, 2009 On Blackboard  Two new links o What the final is going to be link o Questions from past exams (she did not use any of them this year) Tuesday  Anything you want to do Tuesday we will do  I will stare at you until you ask me questions Phase Two Information  User should be able to choose  API documentations o Char class o String class  Don’t have to include all the crap  Just need to include name, data types, etc. You need to know which methods to play around with before the Final  Background information o These are the common ones o Once you get use to them you will be able to use them o The last sheet of the final provided will be API stuff that you don’t need to include on your cheat sheet  The two methods o Differences between Character and String  Char  Does not deal with instance variable  Str  Does stuff with instance variable  o Character  Provides us to have methods  Methods Bruno is interested in  isDigit  isSpace  isLetterOrDigit  IsLetter  isUpperCase  isLowerCase o String  Method types  charAt  equals  equalgnoreCase All instance! All of them! Notice the lack of static. Does stuff with instance variable. All static! All of them!

April 30, 2009  length  compareTo  indewxOf  Substring  toUppercase  toLowerCase  (remember a string is an object)  String name;  creates reference variable  Every time double quotes are used a new string is called  Such as o characterAt o Equals  String are immutable  Never really change  Really another one is created and the other is sent out for trash Example Code [may help with phase two hint hint. Don’t expect copy and paste will work]

April 30, 2009 Public boolean setuser(String u){ { if(!valid(u)) return false; id = u; return true; } Private boolean valid(String user) { if(user.length( ) < 5 || user.length( )) > 20) return false; if(user.indexOf)(‘ ’) > = 0) return false; for(int i = 0; i < user.length( ); i++) if(Character.isDigit(user.charAt(i))) return true; return false; } } Import javax.swing JOptionPane; Public class Email { Public static voiod main (String [ ] args) { String email; user oneUser = new User ( ); do{ email = JOptionPane.ShowInputDialog(“What is your Email?”); if(email.substring(email.length( ) – 3. equalsIgnoreCase(“EDU”)) Better to ask what doesn’t fit. Then kick them out. Go to API and find what you need Length in this case. Go to API and find what you need indexOf in this case. “I want you take this string and see where a space is and return positive number.” If nothing then it will return a Ask for an email and if edu Go to API and find what you need substring in this case.

April 30, 2009 if(email.substring(email.indexOf(‘@’) + 1 email.indexOf(‘.’ , email.indexOf(‘@’) -1) .equalsIngoreCase(“GMU”))) while(!oneuser.setUser(email.substring(0, email.indexOf(‘@’) – 1))) Fix it up Import javax.swing JOptionPane; Public class Email { Public static voiod main (String [ ] args) { String email; user oneUser = new User ( ); do{ email = JOptionPane.ShowInputDialog(“What is your Email?”); email = emai.toLowercase( ) if(email.substring(email.length( ) – 3. email = emai.toLowercase( ) (“edu”)) if(email.substring(email.indexOf(‘@’) + 1 email.indexOf(‘.’ , email.indexOf(‘@’) -1) .equals (“GMU”))) while(!oneuser.setUser(email.substring(0, email.indexOf(‘@’) – 1))) Let’s play String name1 = “Bob”, name2 = “Andy”, name3 = “Bob”; if(name1 == name3) Start at position one until the position right before the @