The document outlines the COS 221 class structure for the 2024/2025 academic year, including details on obtaining a personal tutor and the first module test. It emphasizes the essential steps before coding, such as defining tasks, identifying inputs and outputs, and processing data, with examples like calculating simple interest and cylinder volume. Additionally, it includes an assignment to generate exercises based on the lecture content.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
7 views20 pages
Interlude Class
The document outlines the COS 221 class structure for the 2024/2025 academic year, including details on obtaining a personal tutor and the first module test. It emphasizes the essential steps before coding, such as defining tasks, identifying inputs and outputs, and processing data, with examples like calculating simple interest and cylinder volume. Additionally, it includes an assignment to generate exercises based on the lecture content.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20
INTERLUDE CLASS
COS 221 TEAM
2024/2025 Get a Personal Tutor •Open a GROK account. •Upload a slide •Ask questions •Request assessments First Module Test •Sunday [27th April] • 4 pm – 4:40 pm •30 Questions •10 minutes •2 Attempts [Average of both] BEFORE YOU CODE Before You Code •There are basic steps in every programmer’s mind before the first line of code is written.
•We will explore those steps.
1. Define the task •What do you want to build? •What functions will it have? •Who will it serve? Example: Calculate the Simple Interest • Prompt the user to enter the principal amount, interest rate, and time (in years).
• Use the formula:
Interest = (Principal *Rate * Time) \ (100)
• For males, Rate= 2%; For females, Rate= 3%
• Display the computed interest and total amount
(Principal + Interest). 2. What are the Inputs for the program? •Inputs from the user or default inputs in the program •Input from the user • Default datatype String • Must be converted to an appropriate datatype Example: Calculate the Simple Interest • Prompt the user to enter the principal amount, interest rate, and time (in years).
• Use the formula:
Interest = (Principal *Rate * Time) \ (100)
• For males, Rate= 2%; For females, Rate= 3%
• Display the computed interest and total amount
(Principal + Interest). Rough Sheet • Goal • To build a simple interest calculator • Inputs • Principal (double) • Time (integer/double) • Rate (double) • ???? 3. What are the Outputs for this program?
•Will the process produce new values?
•Will it give a piece of information?
•The default value of outputs is String.
Example: Calculate the Simple Interest • Prompt the user to enter the principal amount, interest rate, and time (in years).
• Use the formula:
Interest = (Principal *Rate * Time) \ (100)
• For males, Rate= 2%; For females, Rate= 3%
• Display the computed interest and total amount
(Principal + Interest). Rough Sheet • Goal • To build a simple interest calculator • Inputs • Principal (double) • Time (integer/double) • Rate (double) • Sex • Output • Interest (double) • New Principal (double) 4. Processes within the Program? • How will the program process data(input) to information(output)? • What is the flow of these processes? • Look out for implicit or explicit verbs(action words/statements)
• The first default process is declaring/initialising your variable
(inputs and outputs)
• This is where the bulk of programming is, from simple
processes like setting a text to be displayed (i.e hello world) to creating a program with various operations and methods. Example: Calculate the Simple Interest • Prompt the user to enter the principal amount, interest rate, and time (in years).
• Use the formula:
Interest = (Principal *Rate * Time) \ (100)
• For males, Rate= 2%; For females, Rate= 3%
• Display the computed interest and total amount
(Principal + Interest). Rough Sheet • Goal • Processes • To build a simple interest • Declare/Initialise variables calculator • Ask the user for values • Inputs • Check the sex of the user • Principal (double) • Initialise the formula • Time (integer/double) • Get the New Principal • Rate (double) • Display outputs • Sex • Output • Interest (double) • New Principal (double) BEFORE YOU CODE •Define the Task •Inputs •Outputs •Processes QUESTIONS? Next-Class Exercise Calculate the Volume of a Cylinder • Prompt the user to enter a cylinder’s radius and height.
• Calculate the volume using the formula:
Volume = π * radius^2 * height Use π=3.14.
• Display the result in a message dialogue using
JOptionPane. ASSIGNMENT •Go to your “Personal tutor” (GROK) • Upload Lecture 2 slides or this slide • Prompt it to generate five(5) more exercises similar to the one in the slide • Do what we just did to each of the generated exercises.