Lab If-Else
Lab If-Elseimport javax.swing.JOptionPane;public class IncomeTax{public IncomeTax() {}
public static void main(String[] args) {IncomeTax display = new IncomeTax();double net,tax,fivePercentTax, tenPercentTax;String netIcome = JOptionPane.showInputDialog("Enter a number of netIcome:");net = Double.parseDouble(netIcome);
if (net <= 15000)tax = 0;else{fivePercentTax = 0.05*15000;tenPercentTax = 0.10*(net - 30000);tax = (fivePercentTax + tenPercentTax);}JOptionPane.showMessageDialog(null, "Tax due = $" + tax);
System.out.println("Tax due = $ " + tax );System.exit(0);
}}
Lab Scanner
Lab Scannerimport java.io.BufferedReader;import java.io.InputStreamReader;import java.io.IOException;public class keyboard{ public keyboard() { } public static void main(String[] args) throws IOException{ BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a number:"); String str = keyboard.readLine(); int num = Integer.parseInt(str); System.out.println("The number is " + num ); } }
Lab JOptionPane
Lab JOptionPaneimport javax.swing.JOptionPane;
public class JOptionPaneDemo{ public static void main (String[] args) { String myNumber = JOptionPane.showInputDialog("Enter a number:"); int numberOfPods=Integer.parseInt(myNumber); System.out.println("The number is "+ myNumber); System.exit(0); }}