Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- import javax.swing.JOptionPane;
- public class AndOperator
- {
- // p//program that determines if user qualifies for loan, must have annual salary >30'000 and worked there for
- //2or more years
- public static void main(String[] args)
- {
- // these are logical operators NOT comparison
- double salary;
- int years;
- String In;
- In = JOptionPane.showInputDialog("whats ur annual salary");
- salary = Double.parseDouble(In);
- In = JOptionPane.showInputDialog("how long have you worked at ur current job");
- years = Integer.parseInt(In);
- if (salary >= 30_000 && years >= 2)
- {
- JOptionPane.showMessageDialog(null,"yes you qualify");
- }
- else
- {
- JOptionPane.showMessageDialog(null, "no you dont qualify");
- }
- System.exit(0);
- }
- }
- -------------------------------------------------------------------------------
- package lessons;
- import java.util.Scanner;
- public class NotOperator
- {
- public static void main(String[] args)
- {
- // logical operators test two or more boolean expressions
- //prescidence is and(&&), or(||), not(!)
- //unary operator that changes the boolean input to the opposite so if input is true output is false
- Scanner keyboard = new Scanner(System.in);
- Double temp;
- System.out.println("enter a temp");
- temp = keyboard.nextDouble();
- if (!(temp > 100))// if smaller argument is true it is turned to false, 'if temp is not greater than 100'
- {
- System.out.println("below max temp");
- }
- else
- {
- System.out.println("above max temp");
- }
- keyboard.close();
- }
- }
- ------------------------------------------------------------------------------------------
- package lessons;
- import java.util.Scanner;
- public class NumericRanges
- {
- //determines if value is within specific range of values
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- int x;
- System.out.println("enter value for x");
- x = keyboard.nextInt();
- if (x >= 20 && x <=40 )
- {
- System.out.println("num is between 20-40");
- }
- else
- {
- }
- //check if outside range between 20-40
- if (x < 20 | x > 40 )
- {
- System.out.println("num is between 20-40");
- }
- else
- {
- }
- keyboard.close();
- }
- }
- -----------------------------------------------------------------------------------
- package lessons;
- import javax.swing.JOptionPane;
- public class OrOperator
- {
- public static void main(String[] args)
- {
- double salary;
- int years;
- String In;
- In = JOptionPane.showInputDialog("whats ur annual salary");
- salary = Double.parseDouble(In);
- In = JOptionPane.showInputDialog("how long have you worked at ur current job");
- years = Integer.parseInt(In);
- if (salary >= 30_000 || years >= 2)
- {
- JOptionPane.showMessageDialog(null,"yes you qualify");
- }
- else
- {
- JOptionPane.showMessageDialog(null, "no you dont qualify");
- }
- System.exit(0);
- }
- }
- ----------------------------------------------------------------------
- package act;
- import java.util.Scanner;
- public class SpeedFines
- {
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- int limit, speed, f;
- System.out.print("enter speed limit:");
- limit = keyboard.nextInt();
- System.out.print("enter the recorded speed of the car:");
- speed = keyboard.nextInt();
- int diff = speed - limit;
- if (speed >= 0 && speed <= limit )
- {
- System.out.println("Congratulations, you are within the speed limit!");
- }
- else if (diff >= 1 && diff <= 20)
- {
- f = 100;
- System.out.println("You are speeding and your fine is $"+f);
- }
- else if (diff >= 21 && diff <= 30)
- {
- f = 270;
- System.out.println("You are speeding and your fine is $"+f);
- }
- else if (diff >= 31)
- {
- f = 500;
- System.out.println("You are speeding and your fine is $"+f);
- }
- else
- {
- System.out.println("inavlid speed");
- }
- keyboard.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement