StringAss - private static int check(String s String temp = null char tc s = s.trim if(s.length!= 13 return 2 else temp = s.substring(3 7

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.regex.Pattern; import javax.swing.JOptionPane; // end of file signal is "end" public class StringAss { public static void main(String[] args){ String s; int v = 0 , ban = 0, inv = 0; do{ s = JOptionPane.showInputDialog("Input the code:"); if (!s.equals("end")){ // System.out.println(s); switch (check(s)){ case 1: ban++; case 0: v++; break; case 2: inv++;break; default: ; } } else break; }while (true); JOptionPane.showMessageDialog(null , "Vailed code entered: " + v + "\nBanned code entered: " + ban + "\nInvailed code entered:" + inv + "\n*Note:Banned code is still count as Vailed code.");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } private static int check(String s) { String temp = null; char tc; s = s.trim(); if (s.length() != 13) return 2; else { temp = s.substring(3, 7); // System.out.println(temp); try{ Integer.parseInt(temp); }catch (NumberFormatException e) { // System.out.println("returned @ line 44"); return 2; } tc = s.charAt(9); // Pattern.compile("^[A-Z]").matcher(tc).find(); if (!Character.isLetter(tc)){ // System.out.println("returned @ line 50"); return 2;} if ((tc == 'R')&&(Integer.parseInt(temp) >= 2000)){ return 1; } return 0; } } }...
View Full Document

This note was uploaded on 03/22/2012 for the course CS 55 taught by Professor Vagada during the Spring '10 term at Santa Monica.

Ask a homework question - tutors are online