Answer:
The Basic Program is as follows:
10 LENGTH = 50
15 WIDTH = 30
20 AREA = WIDTH * LENGTH
25 PRINT AREA
30 END
The Algorithm is as follows:
1. Start
2. Let Length = 50
3. Let Width = 30
4. Compute Area = Length * Width
5. Display Area
6. Stop
See Attachment for flowchart (flowchart is designed using draw io tools)
Explanation:
The flowchart, algorithm and basic program all follow the same sequence and explanation
Using the basic program as a case study;
Line number 10: The program starts by initializing LENGTH to 50
Line number 15: It then initializes WIDTH to 30
Line number 20: The AREA is calculated by LENGTH * WIDTH
Line number 25: The value of AREA is printed afterwards
Line number 30: Lastly, the program stops execution
Answer:
import java.util.Scanner;
public class ANot {
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
System.out.println("How many cookies did you eat today");
int numOfCookies = in.nextInt();
double numCalories = (numOfCookies*300)/4;
System.out.println("The total number of calories you consumed in "+numOfCookies+" cookies is " +
" "+numCalories);
}
}
Explanation:
This code is implemented in Java.
- We know from the question that 4 cookies contain 300 calories
- Therefore number of calories consumed = (number of cookies eaten*300)/4
- To implement this in java we used the scanner class to prompt user for the input
- save the input to a variable and write mathematical expression for the number of calories consumed
- Then output the result