/* Lesley Hogan * July 31st 2003 * WhileOne.java * While loops * Homework from: * http://teachertech.rice.edu/Participants/marilynt/Lessons/Exeter/Programming/whileExer.html */ package net.bunnie.dos; import java.text.DecimalFormat; import net.bunnie.*; public class WhileOne { public static void main (String[] args) { double num; double weight = 208; int i = 500; int z = 0; KeyboardReader r = new KeyboardReader(); DecimalFormat d = new DecimalFormat("0.00"); DecimalFormat dec = new DecimalFormat("#.#"); Echo.e("Please enter a number: "); num = r.readDouble() - .5; while (num > 0) { if (num - .5 > 0) { Echo.e(dec.format(num) + ", "); } else { Echo.e(dec.format(num) + "\n"); } num -= .5; } Echo.e("\n"); while (i > 0) { if ((i % 7 == 0) || (i % 5 == 0)) { if (i >= 100) { Echo.e(i + ", "); } else if (i >= 10) { Echo.e(" " + i + ", "); } else if (i != 5) { Echo.e(" " + i + ", "); } else { Echo.e(" " + i + "\n"); } z++; } i--; } Echo.e(z + " numbers found\n\n"); while (weight > 0) { Echo.e("Weight of package: "); weight = r.readDouble(); if (weight > 0) { if (weight < 10) { Echo.e("Handling/Shipping Charge: $5.00\n\n"); } else { Echo.e("Handling/Shipping Charge: $" + d.format(((.25 * (weight - 10)) + 5)) + "\n\n"); } } else { Echo.e("\nEnd of Program\n\n"); } } } }