WHILE Loop Flowchart & Pseudocode, Decimal Format

TypeSafeReadInt

%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-04-%e4%b8%8b%e5%8d%886-31-23%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-04-%e4%b8%8b%e5%8d%886-34-53\n means to show on the next line

\t means to add a tab

As we can see in the result, it the user did not enter an integer, the program will keep asking the user to “enter as an integer”.

Ordered Menu

屏幕快照 2016-12-04 下午6.52.30.pngLet’s look at the 2nd line import java.util.DecimalFormat, “Decimal format” is a class and a format method. In line 14, I wrote DecimalFormat money = new DecimalFormat(“$#.00”), therefore, the output will always keep 2 decimal space. # represents the number, 00 represent the required decimal space.

Let’s look at line 20, option=input.next(),charAt(0). input.next() takes only the word before space in the input.  input.next().charAt(0) only takes the first letter of the first word since 0 represent the letter in the 0 position in the input. If I input “Hod Dog”, the program will only take H in the word before space “Hot”.

Both char and String can represent letter, they are slightly different: char option==’c’; OR String option=”c”;

屏幕快照 2016-12-04 下午6.53.43.png

orderCost += 6.99 means orderCost=riderCost+6.99

! means NOT Gate

|| means OR Gate

&& means AND Gate

%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-04-%e4%b8%8b%e5%8d%886-52-00

WhileLoop

%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-04-%e4%b8%8b%e5%8d%887-15-09%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-04-%e4%b8%8b%e5%8d%887-15-26WhileLoop2

%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-04-%e4%b8%8b%e5%8d%887-15-38%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-04-%e4%b8%8b%e5%8d%887-15-55

IMG_2408.JPG

LoopEvenOdd3

屏幕快照 2016-12-04 下午7.23.59.png%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2016-12-04-%e4%b8%8b%e5%8d%887-18-37


Personal Reflection: We have started writing long programs which required us to be meticulous and always conscious about the order, syntax, and format. I stuck while writing the last program.  It turns out that there is just an order error between two sentences.  Also, there are many ways of writing to achieve one single purpose, I should always consider whether there are other more effective and efficient ways to write the program.


留下评论