diff --git a/resources/interface.py b/resources/interface.py index e4e96fb10bf6517316f8c262c7e1f74fde7df4ef..53f8178632b85308f772015c1de7551fdc2410c6 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 857132cac8779af8972ab189da24c6ec2dfa6ddf..e1b694d238a19a210c8356d77f1e85d11905edf6 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): """