TypeSafeReadInt
\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
Let’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”;
orderCost += 6.99 means orderCost=riderCost+6.99
! means NOT Gate
|| means OR Gate
&& means AND Gate