Likes

Java Lab_8_Ans_4

Paras comma-delimited text and convert the data into Shirt objects.

SOLUTION



you have been given some comma-delimated shirt data . parse the data . store it in shirt
objects and print the results. the output from the program should like the following.

=== Shirt List ===

Shirt ID: S001

Description: Black Polo Shirt

Color: Black

Size: XL

Shirt ID: S002

Description: Black Polo Shirt


Color: Black

Size: L

Shirt ID: S003

Description: Blue Polo Shirt

Color: Blue

Size: XL

Shirt ID: S004

Description: Blue Polo Shirt

Color: Blue

Size: M

Shirt ID: S005

Description: Tan Polo Shirt

Color: Tan

Size: XL

Shirt ID: S006

Description: Black T-Shirt

Color: Black

Size: XL

Shirt ID: S007

Description: White T-Shirt

Color: White

Size: L

Shirt ID: S008

Description: White T-Shirt

Color: White

Size:L

Open the StringPractice01 project and make the following changes.

1 Edit the main method of the StringSplitTest . java file.

2 Parse each line of the shirts array. Create a shirt object for each
  line and add the shirts to a List. A for loop tp perform
  these steps could be as follows.

   for (Stirng curLine:shirts){
     String[] e = curLine . split(",");
     shirtList . add(new Shirt(e[0], e[1], e[2], e[3] ) );
  }

3 Print out the list of shirts. A loop to do this could be like the
  following.

  System.out.println("=== Shirt List ===");
  for (Shirt shirt:shirtsList){
    System.out.println(shirt . toString() );
  }

4 Run the StringSplitList . java file and verify that your output is similar

No comments: