Permalink
Browse files

assignment 3!

  • Loading branch information...
1 parent cef1d12 commit b2d8b04334b2c062d216715dbc9a6842c3425fac @tvillia committed May 11, 2012
@@ -103,6 +103,8 @@
isa = PBXGroup;
children = (
0E6F215314F9FDFC004F682D /* Images */,
+ 6E69856F152151780035760F /* Review.h */,
+ 6E698570152151780035760F /* Review.m */,
0E02F6BB14CD10E300C3EAE8 /* Restaurant.h */,
0E02F6BC14CD10E300C3EAE8 /* Restaurant.m */,
0EE5A6E214BEB490006BB5E1 /* AppDelegate.h */,
@@ -114,8 +116,6 @@
0EE5A6EC14BEB491006BB5E1 /* DetailViewController.m */,
0E2AFF8414DE3F3600456523 /* Mug.h */,
0E2AFF8514DE3F3600456523 /* Mug.m */,
- 6E69856F152151780035760F /* Review.h */,
- 6E698570152151780035760F /* Review.m */,
0EE5A6DA14BEB490006BB5E1 /* Supporting Files */,
);
path = Restaurants;
@@ -6,15 +6,17 @@
#import <UIKit/UIKit.h>
#import "Restaurant.h"
+#import "Review.h"
+
-@class Review;
@interface DetailViewController : UIViewController
{
Restaurant* restaurant;
}
+@property (readwrite, strong) Restaurant* restaurant;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UINavigationItem *navigationHeader;
@property (weak, nonatomic) IBOutlet UILabel *cuisineLabel;
@@ -28,6 +30,5 @@
@property (weak, nonatomic) IBOutlet UIImageView *star4;
@property (weak, nonatomic) IBOutlet UIImageView *star5;
-- (Review *) findMostHelpfulReview;
@end
@@ -8,26 +8,26 @@
#import "Review.h"
@implementation DetailViewController
+
@synthesize addressLabel;
@synthesize navigationHeader;
@synthesize cuisineLabel;
@synthesize ageLabel;
@synthesize helpfulReviewPercentageLabel;
@synthesize helpfulReviewLabel;
+@synthesize restaurant;
+
@synthesize star1;
@synthesize star2;
@synthesize star3;
@synthesize star4;
@synthesize star5;
--(Review *)findMostHelpfulReview
-{
- return nil;
-}
-
#pragma mark - View lifecycle
- (void)viewDidLoad
+
+
{
[super viewDidLoad];
restaurant = [[Restaurant alloc] init];
@@ -37,6 +37,9 @@ - (void)viewDidLoad
restaurant.cuisineType = @"Peruvian";
restaurant.yearOpened = 1995;
+
+ Review* findMostHelpfulRatings=[restaurant mostHelpfulRatings];
+
Review* review1 = [[Review alloc] init];
review1.text = @"What fab-u-lass chicken! We could eat it all day if we didn't have to stop to drink sangria!";
// review1.reviewer = @"The Addams";
@@ -65,17 +68,56 @@ - (void)viewDidLoad
review4.numberOfHelpfulRatings = 14;
review4.numberOfUnhelpfulRatings = 5;
- NSArray* array = [[NSArray alloc] initWithObjects:review1, review2, review3, review4, nil];
+ Review* review5 = [[Review alloc] init];
+ review5.text = @"The food was so awful! I think they cook everything in a trashcan!";
+ // review4.reviewer = @"Greg";
+ review5.score = 3;
+ review5.numberOfHelpfulRatings = 20;
+ review5.numberOfUnhelpfulRatings = 3;
+
+
+
+
+ NSArray* array = [[NSArray alloc] initWithObjects:review1, review2, review3, review4, review5, nil];
NSArray* reviews = [restaurant reviews];
- for (id review in reviews) { }
addressLabel.text = [restaurant address];
navigationHeader.title = [restaurant name];
cuisineLabel.text = [restaurant cuisineType];
ageLabel.text = [NSString stringWithFormat:@"Est. %i (%i years ago)", restaurant.yearOpened, [restaurant age]];
- helpfulReviewLabel.text = [NSString stringWithFormat: review3.text, [review3 ReviewerName]];
- helpfulReviewPercentageLabel.text = [NSString stringWithFormat: @"%i helpful reviews out of %i", review3.numberOfHelpfulRatings, [review3 total]];
+
+ Review* mostHelpful=[restaurant mostHelpfulRatings];
+
+ helpfulReviewLabel.text = [mostHelpful text];
+ if (helpfulReviewLabel.text == nil) {
+ helpfulReviewLabel.text = @"Not enough helpful reviews yet.";
+ }
+
+ helpfulReviewPercentageLabel.text = [NSString stringWithFormat: @"%i helpful reviews out of %i", review3.numberOfHelpfulRatings, [review3 total]];
+
+ if (helpfulReviewPercentageLabel.text == nil) {
+ helpfulReviewPercentageLabel.text = @" ";
+ }
+
+ if (([restaurant averageCustomerReview] > 0.1) && ([restaurant averageCustomerReview] < 1.45)) {
+ star1.image = [UIImage imageNamed:@"Star_ON.png"];
+ }
+ if (([restaurant averageCustomerReview] > 1.5) && ([restaurant averageCustomerReview] < 2.45)) {
+ (star2.image = [UIImage imageNamed:@"Star_ON.png"]) && (star1.image = [UIImage imageNamed:@"Star_ON.png"]);
+ }
+ if (([restaurant averageCustomerReview] > 2.5) && ([restaurant averageCustomerReview] < 3.45)) {
+ (star2.image = [UIImage imageNamed:@"Star_ON.png"]) && (star1.image = [UIImage imageNamed:@"Star_ON.png"]) && (star3.image = [UIImage imageNamed:@"Star_ON.png"]);
+ }
+ if (([restaurant averageCustomerReview] > 3.5) && ([restaurant averageCustomerReview] < 4.45)) {
+ (star2.image = [UIImage imageNamed:@"Star_ON.png"]) && (star1.image = [UIImage imageNamed:@"Star_ON.png"]) && (star3.image = [UIImage imageNamed:@"Star_ON.png"])&&
+ (star4.image = [UIImage imageNamed:@"Star_ON.png"]);
+ }
+ if (([restaurant averageCustomerReview] > 4.5) && ([restaurant averageCustomerReview] < 4.45)) {
+ (star2.image = [UIImage imageNamed:@"Star_ON.png"]) && (star1.image = [UIImage imageNamed:@"Star_ON.png"]) && (star3.image = [UIImage imageNamed:@"Star_ON.png"]) &&
+ (star4.image = [UIImage imageNamed:@"Star_ON.png"])&&
+ (star5.image = [UIImage imageNamed:@"Star_ON.png"]);
+ }
}
View
@@ -4,14 +4,15 @@
//
#import <Foundation/Foundation.h>
+#import "Review.h"
@interface Restaurant : NSObject
{
NSString* address;
NSString* name;
NSString* cuisineType;
int yearOpened;
- NSArray* reviews;
+ NSMutableArray* reviews;
@@ -20,8 +21,10 @@
@property(readwrite, strong) NSString* name;
@property(readwrite, strong) NSString* cuisineType;
@property(readwrite) int yearOpened;
-@property(readwrite, strong) NSArray* reviews;
+@property(readwrite, strong) NSMutableArray* reviews;
-(int)age;
+-(Review*) mostHelpfulRatings;
+-(float) averageCustomerReview;
@end
View
@@ -4,7 +4,7 @@
//
#import "Restaurant.h"
-
+#import "Review.h"
@implementation Restaurant
@synthesize address, name, cuisineType, yearOpened, reviews;
@@ -15,4 +15,42 @@ -(int)age
return 2012 - yearOpened;
}
+-(Review*) mostHelpfulRatings
+{
+ Review* mostHelpfulRatings = nil;
+
+ for (Review* review in reviews)
+ {
+ if (review.numberOfHelpfulRatings > 4)
+ {
+ if (mostHelpfulRatings == nil) {
+ mostHelpfulRatings = review;
+ }
+
+ if(review.percentage > mostHelpfulRatings.percentage)
+ {
+ mostHelpfulRatings = review;
+ }
+ }
+
+ }
+
+ NSLog (@"Review Text: %@", mostHelpfulRatings.text);
+ return mostHelpfulRatings;
+
+}
+
+-(float) averageCustomerReview
+{
+ int sum = 0;
+ for (Review* storage in reviews)
+ {
+ sum+= [storage score];
+ }
+
+ return (float) sum/[reviews count];
+}
+
+
+
@end
View
@@ -27,6 +27,7 @@
@property(readwrite) int numberOfHelpfulRatings;
@property(readwrite) int numberOfUnhelpfulRatings;
-(int) total;
+-(float) percentage;
@end
// @property(readwrite, strong) NSString* address;
View
@@ -21,4 +21,6 @@ -(float) percentage
return (float)numberOfHelpfulRatings / (numberOfUnhelpfulRatings + numberOfHelpfulRatings);
}
+
+
@end

0 comments on commit b2d8b04

Please sign in to comment.