import java.text.NumberFormat; import uwcse.io.*; /** * Practicing using conditionals */ public class Conditionals { /** * A method to illustrate the use of de Morgan's laws */ public void testDeMorganLaws() { // ask for the family income // ask for the number of children // if the family income is not greater than 20000 // or if the number of children is greater than 3 // display a message stating that the family might // be eligible for a stipend // do this in 2 ways // Input double income; int children; // Test for the stipend eligibility in 2 ways // Both ways should give the same result // 1) write the condition with an || (or) // 2) write the condition with an && (and) } public void printGrade() { // given a grade between 0 and 100 // print the corresponding letter grade // 90-100 is A, 80-89 is B, 70-79 is C, 60-69 is D, below 60 is F // // use an if-else if structure // // do the same with a switch statement // Input int grade; // the uw library class Input creates an object to input values // from the keyboard Input in = new Input(); grade = in.readInt("Enter a numerical grade (between 0 and 100): "); // The grade must be between 0 and 100 if (grade > 100 || grade < 0) { System.out.println("Input error"); return; } // Print the letter grade using nested ifs if (grade >= 90) { System.out.println("A"); } else if (grade >= 80) { System.out.println("B"); } else if (grade >= 70) { System.out.println("C"); } else if (grade >= 60) { System.out.println("D"); } else { System.out.println("F"); } // Print the letter grade using a switch switch (grade / 10) { case 10: case 9: System.out.println("A"); break; case 8: System.out.println("B"); break; case 7: System.out.println("C"); break; case 6: System.out.println("D"); break; default: System.out.println("F"); break; } } /** * more ifs */ public void reportToIRS() { // IRS informants are paid cash awards based on the // value of the money recovered. If the information // was specific enough to lead to a recovery, the // informant receives 10 percent of the first $75,000, // 5 percent of the next $25,000 and 1 percent of the // remainder, up to a maximum award of $50,000. // Write a function that takes as input the amount of // the recovery and returns the award. // Test your program by having main call the function // for different amounts. // input the amount recovered double moneyBack; // compute and print the reward // for the display try NumberFormat.getCurrencyInstance() } private double computeReward(double m) { return 0; } public static void main(String[] args) { Conditionals c = new Conditionals(); c.printGrade(); } }