liangm20

Questions 62 and 64

Oct 7th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. Question 62:
  2.  
  3. import java.util.*;
  4. public class question62
  5. {
  6. public static void main(String [] args)
  7. {
  8. scanner1();
  9. }
  10. public static void scanner1()
  11. {
  12. Scanner variableA = new Scanner(System.in); //scanner for variable a
  13. System.out.print("Give me a value for variable a. ");
  14. double a = variableA.nextDouble();
  15. System.out.println();
  16. Scanner variableB = new Scanner(System.in); //scanner for variable b
  17. System.out.print("Give me a value for variable b. ");
  18. double b = variableB.nextDouble();
  19. System.out.println();
  20. Scanner variableC = new Scanner(System.in); //scanner for variable c
  21. System.out.print("Give me a value for variable c. ");
  22. double c = variableC.nextDouble();
  23. System.out.println("One of the answers is " + ((-b+(Math.sqrt(((b*b)-(4*a*c)))))/(2*a))); //formula for one of quadratic answers
  24. System.out.print("The other answer is " + ((-b-(Math.sqrt(((b*b)-(4*a*c)))))/(2*a))); //formula for the other quadratic answer
  25. //the formulas work for the first 2 inputs in question 62
  26. //when the third set of inputs are inserted, it doesn't work (outputs "NaN" because it gives imaginary numbers)
  27. }
  28. }
  29.  
  30. Question 64:
  31.  
  32. public class main64 //main class; class Point is an object of main64
  33. {
  34. public static void main(String[] args)
  35. {
  36. System.out.println("The point is (" + object1.scanner() + "," + object1.scanner2() + ")"); //output for one of the points
  37. System.out.println("The second point is (" + object2.scanner3() + "," + object2.scanner4() + ")"); //output for the other point
  38. }
  39. }
  40.  
  41. import java.util.*;
  42. public class object1 //object of Point, which is an object of class main64; scanner for one of the 2 points inputted by the user
  43. {
  44. public static int scanner()
  45. {
  46. Scanner coordinate = new Scanner(System.in); //scanner for x coordinate
  47. System.out.println("Type in the x coordinate.");
  48. int x = coordinate.nextInt();
  49. return x;
  50. }
  51. public static int scanner2()
  52. {
  53. Scanner coordinate2 = new Scanner(System.in); //scanner for y coordinate
  54. System.out.println("Type in the y coordinate.");
  55. int y = coordinate2.nextInt();
  56. return y;
  57. }
  58. }
  59.  
  60. import java.util.*;
  61. public class object2 //object of Point, which is an object of class main64; scanner for the other point inputted by the user
  62. {
  63. public static int scanner3()
  64. {
  65. Scanner coordinate = new Scanner(System.in); //scanner for x coordinate
  66. System.out.println("Type in another x coordinate.");
  67. int x = coordinate.nextInt();
  68. return x;
  69. }
  70. public static int scanner4()
  71. {
  72. Scanner coordinate2 = new Scanner(System.in); //scanner for y coordinate
  73. System.out.println("Type in another y coordinate.");
  74. int y = coordinate2.nextInt();
  75. return y;
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment