Lesson 4 If Else If Condition statement to Compute Scholarship discount using Relational Operators Sample Program Explained



Logical Operators Example Statement • && and • || Or • ! Not Problem : if else if • Input grade , determine if grade is 100-99 to avail 100% discount, 96-98 to avail 50% discount 94-95 25% discount otherwise no discount. Compute and display discount and amount due. 1. Input name, grade , tuition 2. Determine the discount : if grade is 100-99 to avail 100% discount, 96-98 to avail 50% discount 94-95 25% discount otherwise no discount. 3. Compute and display discount and amount due.


package ifelseif_scholarship; import java.io.*; import javax.swing.*; public class IfElseIf_Scholarship { public static void main(String[] args) { //declare global variables double grade, discount,tuitionFee ,amountDue; String name,scholarship_grant; name=JOptionPane.showInputDialog(null, "Enter your name"); grade =Double.parseDouble(JOptionPane.showInputDialog(null,"Enter your grade")); tuitionFee =Double.parseDouble(JOptionPane.showInputDialog(null,"Enter your tuitionFee")); if(grade>=99 && grade <=100) { discount = tuitionFee*1; scholarship_grant = " 100% Scholarship Grant" ; } else if(grade >=96 && grade <99) { discount = tuitionFee*.50; scholarship_grant = " 50% Scholarship Grant" ; } else if(grade >=94 && grade <96) { discount = tuitionFee*.25; scholarship_grant = " 25% Scholarship Grant" ; } else { discount = 0; scholarship_grant = " No Scholarship Grant" ; } amountDue=tuitionFee-discount; scholarship_grant = "Name :" + name +"\nScholarship Grant"+scholarship_grant+ "\nGrade : "+grade+ "\n Tuition Fee " +tuitionFee+" \nDiscount :" +discount+"\nAmount Due:" +amountDue; JOptionPane.showMessageDialog(null,scholarship_grant); } }

Comments

Popular posts from this blog

Exercise HTML Basics