Question

Your task for this project is to write a parser for a customer form. You need to develop a Java application using Parboiled l

  a hyphen, and four digits. Examples Here are some input examples for your program: John Doe 3609 Mynders Ave, Memphis, TN, Un

Your task for this project is to write a parser for a customer form. You need to develop a Java application using Parboiled library. Your program should include a grammar for the parser and display the parse tree with no errors. Remember that your fifth and sixth assignments are very similar to this project and you can benefit from them. The customer form should include the following structure: First name, middle name (optional), last name Street address, city, state (or province), country Phone number Rules First name, middle name and last name should start with an uppercase letter followed by lower . The street address can include any type of letters or numbers. There is no lowercase/uppercase The city name should start with an uppercase letter followed by lowercase/uppercase letters. case letters. Middle name is an optional input meaning such an input may or may not exist. restriction either The state or province should start with an uppercase letter followed by lowercase/uppercase letters The country name should start with an uppercase letter followed by lowercase/uppercase letters The phone number should begin with area code in parenthesis, followed by a space, three digits, . .
a hyphen, and four digits. Examples Here are some input examples for your program: John Doe 3609 Mynders Ave, Memphis, TN, United States of America (901) 345-9834 Joshua R. Clemens 982 Pryor St, Little Rock, AR, USA (501) 876-1234 Mary Smith 82 Main St., Toronto, Ontario, Canada (416) 509-6995 Please do everything on your own and submit your project in a zip file. Your zip folder should include your project along with its source files, screenshots of sample input, and screenshots of outputs
0 0
Add a comment Improve this question Transcribed image text
Answer #1

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU

RATE THUMBSUP PLEASE

ANSWER:

CODE:

import java.util.*;

class Validation{

public static void main(String args[]){

Scanner in = new Scanner(System.in);

String name, fname, lname, mname, address, st_address, city, state, country, phone;

while(true){

System.out.print("Enter name: ");

name = in.nextLine();

StringTokenizer st = new StringTokenizer(name, " ");

if(st.countTokens()<2)

System.out.println("Invalid name, must be Firstname Middlename(optional) Lastname");

else{

boolean valid = true;

while(st.hasMoreTokens()){

if(!isValidName(st.nextToken())){

System.out.println("Invalid name, Firstname, Middlename, Lastname should start with an uppercase letter followed by lower case letters");

valid = false;

}

}

if(valid)

break;

}

}

while(true){

System.out.print("Enter address: ");

address = in.nextLine();

StringTokenizer st = new StringTokenizer(address, ",");

if(st.countTokens()<4)

System.out.println("Invalid name, must be Firstname Middlename(optional) Lastname");

else{

boolean valid = true;

int i=0;

while(st.hasMoreTokens()){

if(i==0){

st.nextToken();

i++;

continue;

}

if(!isValidAddress(st.nextToken())){

System.out.println("Invalid address, Street address, city, state (or province), country should start with an uppercase letter followed by lower case letters");

valid = false;

break;

}

}

if(valid)

break;

}

}

while(true){

System.out.print("Enter Phone number: ");

phone = in.nextLine();

if(isValidPhone(phone))

break;

System.out.println("Invalid Phone number, should begin with area code in parenthesis, followed by a space, three digits, a hyphen, and four digits.");

}

System.out.println("\nEntered Details are: ");

System.out.println(name+"\n"+address+"\n"+phone);

}

public static boolean isValidName(String str){

if(str.length()==0)

return false;

if(str.charAt(0)<'A' || str.charAt(0)>'Z')

return false;

for(int i=1; i<str.length(); i++){

if((str.charAt(i)<'a' || str.charAt(i)>'z') && str.charAt(i)!=' ' && str.charAt(i)!='.')

return false;

}

return true;

}

public static boolean isValidAddress(String str){

str = str.trim();

if(str.length()==0)

return false;

if(str.charAt(0)<'A' || str.charAt(0)>'Z')

return false;

for(int i=1; i<str.length(); i++){

if((str.charAt(i)<'a' || str.charAt(i)>'z') && (str.charAt(i)<'A' || str.charAt(i)>'Z') && str.charAt(i)!=' ' && str.charAt(i)!='.')

return false;

}

return true;

}

public static boolean isValidPhone(String mobile){

if(mobile.length()!=14)

return false;

if(mobile.charAt(0)=='(' && mobile.charAt(4)==')' && mobile.charAt(5)==' ' && mobile.charAt(9)=='-'){

if(Integer.parseInt(mobile.substring(1, 3))!=0 && Integer.parseInt(mobile.substring(6, 8))!=0 && Integer.parseInt(mobile.substring(10, 13))!=0)

return true;

}

return false;

}

}

RATE THUMBSUP PLEASE

THANKS

Add a comment
Know the answer?
Add Answer to:
Your task for this project is to write a parser for a customer form. You need to develop a Java a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java project that reads a sequence of up to 25 pairs of names and...

    Write a java project that reads a sequence of up to 25 pairs of names and postal (ZIP) codes, street address, city, state, and 10-digit phone number for individuals. Store the data in an object designed to store a first name (string), last name (string), and postal code (integer), street address (string), city( string), state (string), and 10-digit phone number (long integer, contains area code and does not include special characters such as '(', ')', or '-' . Assume each...

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • Write a Java program that checks the properness of a given variable name. More specifically, your...

    Write a Java program that checks the properness of a given variable name. More specifically, your program should specify whether a user-entered variable name is illegal (no spaces allowed, must begin with a letter) legal, but uses poor style (should only use letters or digits) good You don’t need to check for an uppercase letter for the first letter in the second word, third word, etc. Sample session: This program checks the properness of a proposed Java variable name. Enter...

  • in a java application need  to create an application which prompts the user numerator and denominator values...

    in a java application need  to create an application which prompts the user numerator and denominator values then show the result of the division.  The application will use exception handling to verify the user has entered valid input and will continue to prompt the user for input as long as the value they enter is invalid.  Once the user has entered valid numerator and denominator values, the result is shown and the application exits. had some issues when I entered letters instead of...

  • hello. i need help with number 2 ONLY 1. Use if statements to write a Java...

    hello. i need help with number 2 ONLY 1. Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way 2=ABC 3 = DEF 4 GHI 5 JKL 6 - MNO 7 - PRS 8 - TUV 9-WXY No digit corresponds to either Qor Z. For these 2 letters your program should print a message indicating that they...

  • In C++, You are given a file of customer data with records in the following format...

    In C++, You are given a file of customer data with records in the following format : account number, last name, first name, middle name. Write a program to convert the input data and display it to the monitor in the following format : Accout Name     Logon ID Initial Pswd 21-88282712-B Keith S. Adams ADAM21 Adam88282 08-36847734-A John R. Sturm STUR08 Stur36847    etc. Notes :     1) The account number on the input is 10 digits     2)  The names on...

  • Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses:...

    Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses: Exception handling File Processing(text) Regular Expressions Prep Readings: Absolute Java, chapters 1 - 9 and Regular Expression in Java Project Overview: Create a Java program that allows a user to pick a cell phone and cell phone package and shows the cost. Inthis program the design is left up to the programmer however good object oriented design is required.    Project Requirements Develop a text...

  • Need Solution in JAVA Up until this deliverable, you should have finished your design (it should...

    Need Solution in JAVA Up until this deliverable, you should have finished your design (it should include the CFG in JAVA) and be ready to start the implementation of your toy compiler (or parser). In this project deliverable, you are required to submit all artifacts resulted from your efforts devoted to the course project. Specifically, you should Summarize your design of the toy compiler (or parser), including but not limited to keywords, variables, operators, statements, etc. (recall the in-class demo...

  • write in java and please code the four classes with the requirements instructed You will be...

    write in java and please code the four classes with the requirements instructed You will be writing a multiclass user management system using the java. Create a program that implements a minimum of four classes. The classes must include: 1. Employee Class with the attributes of Employee ID, First Name, Middle Initial, Last Name, Date of Employment. 2. Employee Type Class that has two instances of EmployeeType objects: salaried and hourly. Each object will have methods that calculates employees payrol...

  • Need help in C (a) Write a C program to read in a line of text...

    Need help in C (a) Write a C program to read in a line of text and count the occurrence of each English alphabet. The lowercase version of a letter is considered the same as the uppercase. To make viewing easy, the frequencies should be presented using a bar chart as follows. You can assume that the input contains only spaces, lowercase letters, uppercase letters and the newline character (i.e. the Enter key). Enter a line of text: Letter ZZz...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT