From a16612b64b45ff4faf51c51e42320f799eaf8e05 Mon Sep 17 00:00:00 2001 From: brodriguez8774 <brodriguez8774@gmail.com> Date: Thu, 26 Sep 2019 19:39:07 -0400 Subject: [PATCH] Implement a few interface functions --- resources/interface.py | 20 ++++++++++++++++++++ resources/knapsack.py | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/resources/interface.py b/resources/interface.py index e4e96fb..53f8178 100644 --- a/resources/interface.py +++ b/resources/interface.py @@ -123,11 +123,28 @@ class UserInterface(): """ Sets "Max Weight" value for program. """ + stay_in_function = True + + while stay_in_function: + print('Enter a positive integer for "Max Weight":') + + # Get user's input. + user_input = input() + print('') + + try: + user_input = int(user_input.strip()) + self._knapsack_algorithm.set_max_weight(user_input) + stay_in_function=False + print('"Max Weight" set to {0}'.format(user_input)) + except ValueError: + print('Input value was not a positive integer.') def clear_max_weight(self): """ Resets "Max Weight" value for program to 0. """ + self._knapsack_algorithm.clear_max_weight() def set_item_set_by_json(self): """ @@ -143,6 +160,7 @@ class UserInterface(): """ Removes all items from item set. """ + self._knapsack_algorithm.clear_item_set() #endregion Program Values Menu @@ -150,6 +168,8 @@ class UserInterface(): """ Displays program values for user. """ + self._knapsack_algorithm.display_max_weight() + self._knapsack_algorithm.display_item_set() def solve_knapsack_problem(self): """ diff --git a/resources/knapsack.py b/resources/knapsack.py index 857132c..e1b694d 100644 --- a/resources/knapsack.py +++ b/resources/knapsack.py @@ -88,13 +88,13 @@ class FractionalKnapsackAlgorithm(): """ Prints current item set with logging. """ - logger.info('Current Item Set: {0}'.format(self._item_set_)) + print('Current Item Set: {0}'.format(self._item_set_)) def display_max_weight(self): """ Prints current max weight with logging. """ - logger.info('Current Max Weight: {0}'.format(self._max_weight_)) + print('Current Max Weight: {0}'.format(self._max_weight_)) def calculate_fractional_knapsack(self): """ -- GitLab