Question: help i need to create a java application using jgrasp that Continue to prompt the user for data as long as The Zipcode is not
help i need to create a java application using jgrasp that Continue to prompt the user for data as long as The Zipcode is not numeric or if the user input letters on the Zipcode
public class PrepareTax {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Create object for Scanner
Scanner input=new Scanner(System.in);
//prompt user of tax file number
System.out.print("Enter the tax file number in the format of 999-999-999:");
String tfn=input.next();
/*verify valid or invalid*/
while(!isValidNumber(tfn)){
System.out.print("Enter the valid tax file number:");
tfn=input.next();
}//end while
//prompt the user of the last name
System.out.print("Enter the last name:");
String last=input.next();
//prompt the user of the first name
System.out.print("Enter the first name:");
String first=input.next();
//prompt the user of street name
System.out.print("Enter your address ");
String strt=input.next();
//prompt the user of city name
System.out.print("Enter the city name:");
String cty=input.next();
//prompt the state name
System.out.print("Enter the state name:");
String st=input.next();
//prompt the Zip code
System.out.print("Enter the zip code:");
int zipCode=input.nextInt();
//verify the zip code
while(zipCode<1000||zipCode>9999){
System.out.print("Enter the valid zip code:");
zipCode=input.nextInt();
}//end while
System.out.print("Enter the annual income:$");
double income=input.nextDouble();
//verify annual income
while(income<0){
System.out.print("Enter the valid annual income:$");
income=input.nextDouble();
}//end while
//prompt the user for the marital status
System.out.print("Enter the marital status:");
char ms=input.next().charAt(0);
//verify marital status
while(ms!='S'&&ms!='s'&&ms!='M'&&ms!='m'){
System.out.print("Enter the valid marital status:");
ms=input.next().charAt(0);
}//end while
//create object for TaxReturn class
TaxReturn tr=new TaxReturn(tfn,last,first,strt,cty,st,zipCode,income,ms);
//call to displayData method
tr.displayData();
}//end of main method
//isValidNumber
private static boolean isValidNumber(String tfn){
//verify the length
if(tfn.length()!=11)
return false;
else{
/*repeat loop*/
for(int i=0;i /*return false if the character'-is not at the proper place*/ if((i==3||i==7)&&tfn.charAt(i)!='-') return false; /*return false if any of the character in not the digit*/ if(i!=3&&i!=7&&!Character.isDigit(tfn.charAt(i))) return false; }//end //return true if the number is valid return true; }//end if/else }//end isValidNumber method }//end of PreTax class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
