Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question 62:
- import java.util.*;
- public class question62
- {
- public static void main(String [] args)
- {
- scanner1();
- }
- public static void scanner1()
- {
- Scanner variableA = new Scanner(System.in); //scanner for variable a
- System.out.print("Give me a value for variable a. ");
- double a = variableA.nextDouble();
- System.out.println();
- Scanner variableB = new Scanner(System.in); //scanner for variable b
- System.out.print("Give me a value for variable b. ");
- double b = variableB.nextDouble();
- System.out.println();
- Scanner variableC = new Scanner(System.in); //scanner for variable c
- System.out.print("Give me a value for variable c. ");
- double c = variableC.nextDouble();
- System.out.println("One of the answers is " + ((-b+(Math.sqrt(((b*b)-(4*a*c)))))/(2*a))); //formula for one of quadratic answers
- System.out.print("The other answer is " + ((-b-(Math.sqrt(((b*b)-(4*a*c)))))/(2*a))); //formula for the other quadratic answer
- //the formulas work for the first 2 inputs in question 62
- //when the third set of inputs are inserted, it doesn't work (outputs "NaN" because it gives imaginary numbers)
- }
- }
- Question 64:
- public class main64 //main class; class Point is an object of main64
- {
- public static void main(String[] args)
- {
- System.out.println("The point is (" + object1.scanner() + "," + object1.scanner2() + ")"); //output for one of the points
- System.out.println("The second point is (" + object2.scanner3() + "," + object2.scanner4() + ")"); //output for the other point
- }
- }
- import java.util.*;
- public class object1 //object of Point, which is an object of class main64; scanner for one of the 2 points inputted by the user
- {
- public static int scanner()
- {
- Scanner coordinate = new Scanner(System.in); //scanner for x coordinate
- System.out.println("Type in the x coordinate.");
- int x = coordinate.nextInt();
- return x;
- }
- public static int scanner2()
- {
- Scanner coordinate2 = new Scanner(System.in); //scanner for y coordinate
- System.out.println("Type in the y coordinate.");
- int y = coordinate2.nextInt();
- return y;
- }
- }
- import java.util.*;
- public class object2 //object of Point, which is an object of class main64; scanner for the other point inputted by the user
- {
- public static int scanner3()
- {
- Scanner coordinate = new Scanner(System.in); //scanner for x coordinate
- System.out.println("Type in another x coordinate.");
- int x = coordinate.nextInt();
- return x;
- }
- public static int scanner4()
- {
- Scanner coordinate2 = new Scanner(System.in); //scanner for y coordinate
- System.out.println("Type in another y coordinate.");
- int y = coordinate2.nextInt();
- return y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment