1 00:00:01,250 --> 00:00:03,560 In this lesson, we're going to finalize the application. 2 00:00:05,430 --> 00:00:11,030 The data contains shirts and pants, and you can store each line as an object of the product class, 3 00:00:11,550 --> 00:00:13,380 so I'm going to start by removing this code. 4 00:00:18,430 --> 00:00:20,560 Could a function that returns a product to Ray? 5 00:00:24,300 --> 00:00:25,350 Called Get Data. 6 00:00:28,890 --> 00:00:30,960 And it's going to throw a file not found exception. 7 00:00:35,100 --> 00:00:38,100 All right, now create a new object of the Phalen input stream class. 8 00:00:45,190 --> 00:00:49,180 And the family bitstream is going to connect to products, not text the file name. 9 00:00:52,480 --> 00:00:56,980 And now we can create a new object of the scanner class that's going to pick up the data from the input 10 00:00:56,980 --> 00:00:57,400 stream. 11 00:01:07,710 --> 00:01:12,830 OK, looking back, there are 18 arrows, so we'll need to create a product array that can store 18 12 00:01:12,840 --> 00:01:13,590 objects. 13 00:01:26,760 --> 00:01:33,120 Now, you might think Tikrit a while loop while scandal has next line, but we need a counter that keeps 14 00:01:33,120 --> 00:01:36,690 track of every row so that we can populate the array properly. 15 00:01:37,920 --> 00:01:39,360 So here is a for loop instead. 16 00:01:41,280 --> 00:01:46,200 For it is equal to zero and the loop is going to keep running as long as Skåne has a next line. 17 00:01:47,690 --> 00:01:48,410 Plus, plus. 18 00:01:52,440 --> 00:01:53,400 OK, great. 19 00:01:53,550 --> 00:01:58,470 Now, looking back at the file, notice that the first piece of data tells us what the object is. 20 00:02:03,360 --> 00:02:09,630 So we'll pick up the first value in that line using Scandi next and put it in a switch statement if 21 00:02:09,630 --> 00:02:11,370 that value happens to be pant's. 22 00:02:14,420 --> 00:02:16,850 We're going to set the element at that index I. 23 00:02:19,550 --> 00:02:22,010 Equal to a new object of the class. 24 00:02:23,510 --> 00:02:28,120 Looking back at the data, we got to pick up an ENT double string string next and. 25 00:02:29,500 --> 00:02:30,220 Next double. 26 00:02:34,910 --> 00:02:35,480 Next. 27 00:02:41,040 --> 00:02:41,610 Next. 28 00:02:47,840 --> 00:02:49,700 If that value happens to be a shirt. 29 00:02:57,350 --> 00:02:59,630 We're going to set that element and index I. 30 00:03:01,810 --> 00:03:07,870 Equal to a new object of the class, looking back at the data, we got to pick up a string, double 31 00:03:07,870 --> 00:03:08,740 string string. 32 00:03:14,040 --> 00:03:15,240 So we'll say next. 33 00:03:16,260 --> 00:03:17,040 Next double. 34 00:03:21,200 --> 00:03:22,430 Next and next. 35 00:03:25,790 --> 00:03:28,970 Now, this gives an error because this constructor doesn't exist. 36 00:03:31,970 --> 00:03:35,660 The constructor expects an item type, but we're passing in a string. 37 00:03:39,180 --> 00:03:46,020 What you can actually do is get an enum value from a string, so from the item size will get the enum 38 00:03:46,020 --> 00:03:48,720 value that corresponds to scan next. 39 00:03:56,350 --> 00:04:00,100 So if scandal next to small, we're going to get back in value of small. 40 00:04:02,020 --> 00:04:05,500 If it's medium, we'll get back medium anyways, that's really a. 41 00:04:08,380 --> 00:04:13,690 And so we populated the products array with shirts and pants, that's polymorphism for you right there, 42 00:04:13,990 --> 00:04:17,200 because each child object is taking the form of its parent. 43 00:04:19,760 --> 00:04:21,019 Now, I'll close scanner. 44 00:04:22,750 --> 00:04:24,370 In return, the product to Ray. 45 00:04:27,360 --> 00:04:28,300 And perfect. 46 00:04:28,320 --> 00:04:29,560 That was the hard part. 47 00:04:29,760 --> 00:04:32,070 Now we get to enjoy the fruits of our labor. 48 00:04:38,800 --> 00:04:43,330 Inside, man, we're going to try to call the get data function and store the result in an array. 49 00:04:48,390 --> 00:04:51,290 And will catch the exception if the code happens to fail. 50 00:04:57,840 --> 00:05:00,180 And will print the exception that it comes with it. 51 00:05:03,960 --> 00:05:08,970 And assuming everything works, you're going to sort the array, every object in that array, we know 52 00:05:08,970 --> 00:05:14,130 implements the comparable interface and so the array is going to be sorted alphabetically and by price 53 00:05:14,130 --> 00:05:15,450 because that's how we designed it. 54 00:05:16,730 --> 00:05:20,450 Now run through every product in the product array and print it. 55 00:05:29,140 --> 00:05:31,900 OK, we'll put a break point here, run the debugger. 56 00:05:35,990 --> 00:05:37,160 Step into the function. 57 00:05:43,570 --> 00:05:46,690 OK, first one, a shirt, so with is a shirt object. 58 00:05:56,260 --> 00:05:58,870 Next one is so a store is a pants object. 59 00:06:02,920 --> 00:06:04,360 And I want to skip the rest. 60 00:06:05,370 --> 00:06:07,860 So I'll put another break point and press next. 61 00:06:10,700 --> 00:06:12,920 Here is our array, fully populated. 62 00:06:16,550 --> 00:06:21,410 We'll keep going now, our Arae got sorted pans show up first. 63 00:06:23,310 --> 00:06:29,070 Shirt after in the array is also sorted based on price, that's perfect, will print it. 64 00:06:33,630 --> 00:06:35,340 And that's kind of ugly. 65 00:06:35,520 --> 00:06:37,230 It wouldn't hurt to touch things up. 66 00:06:39,890 --> 00:06:44,360 Go to shirt that java, remove the brackets, they're not various statically pleasing. 67 00:06:45,580 --> 00:06:49,720 A white shirt in the beginning and put a tab of space before each value. 68 00:07:01,700 --> 00:07:03,140 I think they should look pretty nice. 69 00:07:06,120 --> 00:07:07,950 And I'll do the same thing for Pentz. 70 00:07:27,040 --> 00:07:29,400 I'll give you some time to pause and get that done. 71 00:07:35,050 --> 00:07:37,000 OK, I'll rerun my app. 72 00:07:52,320 --> 00:07:53,220 And beautiful.