In the Phone Charge example, to compute final monthly charge, the program needs to:
Input the number of minutes;
Calculate the charge before tax;
Calculate total charge after tax;
Print out total charge;
The above steps have to be executed in this sequence because a latter step depends on a former step's result. This is called sequential execution.
B. The concept of breaking down a big task into smaller subtasks.
Breaking down a big programming task into a series of smaller subtasks is an important "programmers' thinking". It happens at two levels:
1. Break down the original, top-level task into several smaller subtasks
For instance, if a robot wants to calculate the number of windows in a room, it can calculate windows in each wall. In this case, counting windows in each wall is an easier subtask. It also let you adapt your solution to a different geometric shape of the room.Similarly, if you want to print out the black tile pattern in 1.5.1, keep in mind that the computer prints from top to bottom, left to right only. So if you focusing on printing one row at a time, the pattern is made of three different types of rows, which leads to three subtasks.
Print a row of black tiles once;
Repeat several times to print a row that has only left and right boarder;
Print the center row once or twice;
Repeat step 2
Repeat step 1
2. Each of the subtasks can also be broken down even further into more subtasks, and so on.
For instance, to count the windows in a wall, the robot needs to 1) sense each cell; 2)move to the next cell 3) increase counter by 1 if windows detected
Similarly, to print out a row that has only boarders, you need to 1) print out the left boarder; 2) print out the space in between; 3) print out the right boarder
C. Try this:
1. Break down each of the 5 steps in part A into 2 or more subtasks. For example, step 1 can be made of:
Set up a scanner
Take in a double value using the scanner object
2. Apply the process of task breakdown to these problems and write code to implement.