Download Pseudocode document here.
Pseudocode practice
1. Ask user to input amount to saved every month and for how many months.
Calculate and output total that will be saved if monthly interest is 4%.
BEGIN
INPUT monthlySaving
INPUT savingDuration
FOR each month of savingDuration
totalSavings <- totalSavings + monthlySaving + (monthlySaving * 0.04)
END FOR
OUTPUT totalSavings
END
2. Write pseudocode that asks for an unlimited amount of item names and prices to be input. If 0 is input for name then the loop ends. Output the total cost of all items. Output most expensive item (name and price).
BEGIN
INPUT itemName
INPUT itemPrice
highestItem <- itemName
highestPrice <- itemPrice
WHILE itemName!= 0
total <- total + itemPrice
IF highestPrice < itemPrice
highestItem <- itemName
highestPrice <- itemPrice
ENDIF
INPUT itemName
INPUT itemPrice
ENDWHILE
OUTPUT total, highestItem, highestPrice
END
For those who can't even:
String name = JOptionPane.showInputDialog("Enter item name, then press <enter>");
double price = Double.parseDouble(JOptionPane.showInputDialog("Enter item price, then press <enter>"));
double total = 0;
String mostExpItem = name;
double mostExpPrice = price;
while (!name.equals("0")) {
total = total + price;
if (mostExpPrice < price) {
mostExpItem = name;
mostExpPrice = price;
}
name = JOptionPane.showInputDialog("Enter item name, then press <enter>");
price = Double.parseDouble(JOptionPane.showInputDialog("Enter item price, then press <enter>"));
}
System.out.println("Total is: R" + total);
System.out.println("Most expensive item is " + mostExpItem + " at R" + mostExpPrice);