Advertisement
476179

alll of DS4

Oct 30th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. package lessons;
  2. import javax.swing.JOptionPane;
  3. public class AndOperator
  4. {
  5. // p//program that determines if user qualifies for loan, must have annual salary >30'000 and worked there for
  6. //2or more years
  7. public static void main(String[] args)
  8. {
  9. // these are logical operators NOT comparison
  10. double salary;
  11. int years;
  12. String In;
  13. In = JOptionPane.showInputDialog("whats ur annual salary");
  14. salary = Double.parseDouble(In);
  15. In = JOptionPane.showInputDialog("how long have you worked at ur current job");
  16. years = Integer.parseInt(In);
  17.  
  18. if (salary >= 30_000 && years >= 2)
  19. {
  20. JOptionPane.showMessageDialog(null,"yes you qualify");
  21. }
  22. else
  23. {
  24. JOptionPane.showMessageDialog(null, "no you dont qualify");
  25. }
  26. System.exit(0);
  27. }
  28.  
  29. }
  30.  
  31.  
  32.  
  33.  
  34. -------------------------------------------------------------------------------
  35.  
  36.  
  37.  
  38. package lessons;
  39.  
  40. import java.util.Scanner;
  41.  
  42. public class NotOperator
  43. {
  44.  
  45. public static void main(String[] args)
  46. {
  47. // logical operators test two or more boolean expressions
  48. //prescidence is and(&&), or(||), not(!)
  49. //unary operator that changes the boolean input to the opposite so if input is true output is false
  50. Scanner keyboard = new Scanner(System.in);
  51. Double temp;
  52. System.out.println("enter a temp");
  53. temp = keyboard.nextDouble();
  54.  
  55. if (!(temp > 100))// if smaller argument is true it is turned to false, 'if temp is not greater than 100'
  56. {
  57. System.out.println("below max temp");
  58.  
  59. }
  60. else
  61. {
  62. System.out.println("above max temp");
  63. }
  64. keyboard.close();
  65. }
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. ------------------------------------------------------------------------------------------
  74.  
  75.  
  76.  
  77.  
  78.  
  79. package lessons;
  80. import java.util.Scanner;
  81. public class NumericRanges
  82. {
  83. //determines if value is within specific range of values
  84.  
  85. public static void main(String[] args)
  86. {
  87. Scanner keyboard = new Scanner(System.in);
  88. int x;
  89. System.out.println("enter value for x");
  90. x = keyboard.nextInt();
  91.  
  92. if (x >= 20 && x <=40 )
  93. {
  94. System.out.println("num is between 20-40");
  95. }
  96. else
  97. {
  98.  
  99. }
  100.  
  101. //check if outside range between 20-40
  102. if (x < 20 | x > 40 )
  103. {
  104. System.out.println("num is between 20-40");
  105. }
  106. else
  107. {
  108.  
  109. }
  110.  
  111. keyboard.close();
  112. }
  113.  
  114. }
  115.  
  116.  
  117.  
  118.  
  119. -----------------------------------------------------------------------------------
  120.  
  121.  
  122.  
  123.  
  124.  
  125. package lessons;
  126.  
  127. import javax.swing.JOptionPane;
  128.  
  129. public class OrOperator
  130. {
  131.  
  132. public static void main(String[] args)
  133. {
  134. double salary;
  135. int years;
  136. String In;
  137. In = JOptionPane.showInputDialog("whats ur annual salary");
  138. salary = Double.parseDouble(In);
  139. In = JOptionPane.showInputDialog("how long have you worked at ur current job");
  140. years = Integer.parseInt(In);
  141.  
  142. if (salary >= 30_000 || years >= 2)
  143. {
  144. JOptionPane.showMessageDialog(null,"yes you qualify");
  145. }
  146. else
  147. {
  148. JOptionPane.showMessageDialog(null, "no you dont qualify");
  149. }
  150. System.exit(0);
  151. }
  152.  
  153. }
  154.  
  155.  
  156.  
  157. ----------------------------------------------------------------------
  158.  
  159.  
  160.  
  161.  
  162. package act;
  163.  
  164. import java.util.Scanner;
  165.  
  166. public class SpeedFines
  167. {
  168.  
  169. public static void main(String[] args)
  170. {
  171. Scanner keyboard = new Scanner(System.in);
  172. int limit, speed, f;
  173. System.out.print("enter speed limit:");
  174. limit = keyboard.nextInt();
  175. System.out.print("enter the recorded speed of the car:");
  176. speed = keyboard.nextInt();
  177. int diff = speed - limit;
  178. if (speed >= 0 && speed <= limit )
  179. {
  180. System.out.println("Congratulations, you are within the speed limit!");
  181. }
  182. else if (diff >= 1 && diff <= 20)
  183. {
  184. f = 100;
  185. System.out.println("You are speeding and your fine is $"+f);
  186. }
  187. else if (diff >= 21 && diff <= 30)
  188. {
  189. f = 270;
  190. System.out.println("You are speeding and your fine is $"+f);
  191. }
  192. else if (diff >= 31)
  193. {
  194. f = 500;
  195. System.out.println("You are speeding and your fine is $"+f);
  196. }
  197. else
  198. {
  199. System.out.println("inavlid speed");
  200. }
  201.  
  202. keyboard.close();
  203.  
  204.  
  205. }
  206.  
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement