PetParser - Assignment 8 Name Johrdyn Lorden StudentID 1201666366 Lecture MWF 1:30 Description The PetParser class contains a static method

PetParser - Assignment 8 Name Johrdyn Lorden StudentID...

This preview shows page 1 - 2 out of 2 pages.

// Assignment #: 8 // Name: Johrdyn Lorden // StudentID: 1201666366 // Lecture: MWF 1:30 // Description: The PetParser class contains a static // method parseStringToPet that takes a string // containing a pet's information and // create a pet object from it. public class PetParser { public static Pet parseStringToPet(String lineToParse) { String petName = new String("?"); String type = new String("?"); String temp3 = new String(); String temp4 = new String(); String row = new String(); String column = new String(); int date1 = 0; int month1 = 0; int year1 = 0; String place1 = new String("?"); int rowNum = 1; int columnNum = 1; String[] tokens = lineToParse.split("/"); //get the petName if (tokens[0].length() > 0) { petName = tokens[0].trim(); } //get the pet type if (tokens[1].length() > 0) { type = tokens[1].trim(); } //get the birth information inluding date, month, year, and place if (tokens[2].length() > 0) { temp3 = tokens[2].trim(); String[] tokens2 = temp3.split(","); if (tokens2[0].length() > 0) date1 = Integer.parseInt(tokens2[0].trim()); if (tokens2[1].length() > 0) month1 = Integer.parseInt(tokens2[1].trim()); if (tokens2[2].length() > 0) year1 = Integer.parseInt(tokens2[2].trim()); if (tokens2.length == 4 && tokens2[3].length() > 0) place1 = tokens2[3].trim(); } //create a Pet object using extracted information. Pet pet = new Pet(); pet.setPetName(petName); pet.setType(type); pet.setBirthInfo(date1, month1, year1, place1); return pet;
} //end of parseStringToPet } //end of PetParser class

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture