Please include a journal too.
Microsoft Word - CP1401-CP5639-Assignment2-2021-SP53.docx CP1401/CP5639 Assignment 1 © Information Technology @ James Cook University 1/11 CP1401/CP5639 2021 SP53 Assignment 2 Task - Market Garden Simulator: For this assessment, you are to plan and then code a medium-sized console-based program in Python 3. This assignment is designed to help you build skills using: • As in assignment 1: Input, Processing and Output; Decision structures; Repetition structures • New in assignment 2: Functions and random numbers; Lists The assignment also includes a developer's journal – a document you complete as you plan and code your program to help you focus on and improve your process and become a better developer. Incredibly Important: This assignment must not be where you first learn about these topics. The subject is designed to systematically teach you these principles through the lectures (first), then the practicals. You should have practised each programming concept/construct many times before you start using it in your assignment. If you get to a point in your assignment where you're not sure about something, go back and learn from the subject teaching (not on the Internet). Remember: 100% of what you need to know to complete this assignment is taught in the subject. Problem Description: The Market Garden Simulator is a program that simulates the tranquil and refreshing activity of growing your own garden for fun and profit. You have a list of plants, which each generate "food" according to their name length (as everyone knows, longer plant names mean higher profit at market… but they cost more to buy). Each day when you wait and watch, it rains a random amount. This rainfall determines how much food the plants generate, but if you don't get enough rain, a random plant will die. When you have enough food, you can spend some to buy new plants. To increase the biodiversity of your garden, you can't buy plants you already have. The program starts with a welcome, some instructions and four plants. Then there's a repeating menu with the following four options (read the sample output to understand in more detail): • (W)ait o This simulates a day starting with rainfall between 0 and 100mm (think about constants). If you get less than 30mm (did someone say think about constants?) then a random plant from your list will die (and be deleted from the list). Each plant generates an amount of food according to the formula: (random value between 1/2 rainfall and actual rainfall) / 100 * length e.g., if rainfall is 70, then a random value between 0.35 and 0.7 would multiply the length of each plant, so "Sage" plant (4 characters) would produce a result between (0.35 and 0.7 * 4) 1.4 and 2.8 as an integer so 1 to 2, and "Thai Basil" (10 characters) would produce between 3 and 7. • (D)isplay plants o This simply displays the plants in your garden. • (A)dd new plant o You can only add plants you can afford. You can have an infinite number of plants. New plant names cannot be blank; error-check and repeat for blank names. Notice that we have explicitly taught how to handle errors like this using the error checking pattern: https://github.com/CP1404/Starter/wiki/Programming-Patterns#error-checking You may also notice that we have written useful functions for getting valid inputs before, e.g., https://github.com/CP1401/Practicals/tree/master/prac_06#example So… follow what you've been taught and feel confident that you're on the right track! J Plant names should be converted to title case (using Python's .title() string method), so if the user enters "thai BAsIL", it will become "Thai Basil". If you already have the plant in your list, then you will be asked for the name again. When you add a plant, the name length is deducted from your food. CP1401/CP5639 Assignment 1 © Information Technology @ James Cook University 2/11 • (Q)uit o This will end the main menu and show the final details including the plants, the number of days simulated, the number of plants and the amount of food. Notice that you have been taught how to write menus and you know that (Q) should not be a separate option within the menu, but rather the quit loop condition with final actions coded outside the main menu loop: https://github.com/CP1404/Starter/wiki/Programming- Patterns#menus The sample output below will help you understand these details. There is also a video demonstration available. Make sure you understand how the program should work (that's the "analysis" step in program development) before you plan it ("design" step), then code it ("implementation"). Don't forget to test your program thoroughly, comparing it to these requirements. Coding Requirements and Suggestions: • Make use of named constants as appropriate, e.g., for things that would otherwise be "magic numbers", like the maximum rainfall or low rainfall threshold for plant death. Remember the guidelines for constants: if you use a value more than once, it should probably be a constant, and if you have a constant then you must use it in all places that you reference that value. A very good way to test that you have used constants properly is that you should be able to change ONE value in ONE place to make the low rain threshold 20 mm… and the instructions should correctly show this. That's what constants are for. • You are expected to include two kinds of useful comments in each of your program: o Every function should have a """docstring""". See the subject teaching for how to properly write docstrings. o Use # block comments for things that might reasonably need a comment. Do not include unnecessary or many comments as these are just "noise" and make your program harder to read. • Functions should be used for sections of the program and repeated tasks as you have been taught. Follow the DRY (Don't Repeat Yourself) principle and consider turning repeated code into functions. Here are some possibilities for functions: o displaying the plants is done the same way in multiple places o adding a plant is a significant section o getting a plant name looks very similar to the kind of thing we wrote functions for in the teaching (getting a valid string) o simulating a day is a nice-sized section for its own function o the main menu and one-off program behaviour (like the start and end) should all be part of the main function – again, like our examples and teaching • You do not need to handle plant names that aren't plants. It's fine to have a "1401 Rocks" or "Is Monty Fun?" plant. • Sample output from the program is provided. You should ensure that your program mostly matches this and definitely does in terms of meeting the requirements. But you are allowed to be a bit creative and customise the interface as you wish. So, please understand – you can change small details that don't break the requirements, but if you change it substantially you may miss some of the required aspects and lose marks. E.g., you could display the plants differently, or use different output text when a plant dies, but you could not add or remove a menu option and you couldn't choose to not have plants die. Please ask if you are unsure. • The sample output shows "1 plants". This is fine, but you are welcome to add the logic to make this "1 plant". Also, there's a comma at the end of the plants display. This is also fine and you don't need to change it – but you can if you want to. CP1401/CP5639 Assignment 1 © Information Technology @ James Cook University 3/11 We strongly suggest you work incrementally on this task: focus on completing small parts rather than trying to get everything working at once. This is called "iterative development" and is a common way of working, even for professionals. A suggested approach to this is described below: 1. Start with planning and pseudocode – this is important for your process as well as your journal (see below for details about recording your process in your journal). 2. Start coding with the main function and creating a working menu using the pattern you've been taught. For each menu item, just print something (like "… add plant…"). 3. Choose one function/section at a time to implement. E.g., start with the function to display plants and get this working, then call the function from your main menu. 4. When you do a more complex section, keep it simple first, then add complexity. E.g., when adding a plant, ignore the error-checking to start with. Get it working properly, then add error- checking. 5. When writing the function to simulate a day, start with just generating and displaying random rainfall, then add the calculation to determine plant food… but notice the random number or percentage are never printed… so print these as helpful debugging output until your function is working correctly, then remove the print statement. 6. When writing and testing code with randomness, you can encourage it towards what you want to test by modifying your constants or starting values. E.g., when you want to test what happens when it doesn't rain much, change the maximum rainfall from 100 to a low number temporarily (that's how we created the 2nd sample output). Want to test what happens when you run out of plants? Change the starting list to one plant instead of four. Don't waste time running your program many many many times to hopefully get the random scenario you want to test. Journal: A significant desired outcome for this subject is you learning to develop solutions to problems systematically and thoughtfully. That is, we are not only interested in the final product but in your process and the lessons you have learned through your experience. To encourage you in learning the systematic problem-solving process, you will record your work experiences and insights in a simple journal for this assignment – submitted as a PDF file. Each time you work on the assignment, record an entry in your journal that includes: • Date and time you worked, including duration • What you worked on with simple details, enough that someone reading it would understand • Any difficulties