Question

In: Computer Science

ASAP (Algebra: vertex form equations) The equation of a parabola can be expressed in either standard...

ASAP

(Algebra: vertex form equations) The equation of a parabola can be expressed in either standard form (y = ax^2 + bx + c) or vertex form (y = a(x-h)^2 + k). Write a program that prompts the user to enter a, b, and c as integers in standard form and displays h and k in the vertex form. Hint: Use the Rational class in LiveExample 13.13 for computing h and k. Use the template at https://liveexample.pearsoncmg.com/test/Exercise13_21Test.txt for your code. Sample Run 1 Enter a, b, c: 1 3 1 h is -3/2 k is -5/4 Sample Run 2 Enter a, b, c: 2 3 4 h is -3/4 k is 23/8 Class Name: Exercise13_21 If you get a logical or runtime error, please refer https://liveexample.pearsoncmg.com/faq.html.

Solutions

Expert Solution

Hi, Please find the solution and rate the answer. Comments inline. Thanks

package com.company;
import java.util.Scanner;

public class Exercise13_21 {
    static Scanner sc =  new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("Enter the Coefficients");
        System.out.println("Enter a:");
        int a = sc.nextInt();
        System.out.println("Enter b:");
        int b = sc.nextInt();
        System.out.println("Enter c:");
        int c = sc.nextInt();
        //so we need to compute 'h' which is -b/(2*a)
        Rational h =  new Rational((-1)*b,2*a);
        //finding k
        Rational hsquare = new Rational(h.multiply(h).getNumerator(),h.multiply(h).getDenominator());
        Rational first = new Rational(hsquare.multiply(new Rational(a,1)).getNumerator(),hsquare.multiply(new Rational(a,1)).getDenominator());
        Rational second = h.multiply(new Rational(b,1));
        Rational finalAnswer = first.add(second).add(new Rational(c,1));

        System.out.println("Vertex form: h,k"+h+" and k is "+finalAnswer);

    }
}


// Copy from the book
class Rational extends Number implements Comparable<Rational> {
    // Data fields for numerator and denominator
    private long numerator = 0;
    private long denominator = 1;

    /** Construct a rational with default properties */
    public Rational() {
        this(0, 1);
    }

    /** Construct a rational with specified numerator and denominator */
    public Rational(long numerator, long denominator) {
        long gcd = gcd(numerator, denominator);
        this.numerator = (denominator > 0 ? 1 : -1) * numerator / gcd;
        this.denominator = Math.abs(denominator) / gcd;
    }

    /** Find GCD of two numbers */
    private static long gcd(long n, long d) {
        long n1 = Math.abs(n);
        long n2 = Math.abs(d);
        int gcd = 1;

        for (int k = 1; k <= n1 && k <= n2; k++) {
            if (n1 % k == 0 && n2 % k == 0)
                gcd = k;
        }

        return gcd;
    }

    /** Return numerator */
    public long getNumerator() {
        return numerator;
    }

    /** Return denominator */
    public long getDenominator() {
        return denominator;
    }

    /** Add a rational number to this rational */
    public Rational add(Rational secondRational) {
        long n = numerator * secondRational.getDenominator() +
                denominator * secondRational.getNumerator();
        long d = denominator * secondRational.getDenominator();
        return new Rational(n, d);
    }

    /** Subtract a rational number from this rational */
    public Rational subtract(Rational secondRational) {
        long n = numerator * secondRational.getDenominator()
                - denominator * secondRational.getNumerator();
        long d = denominator * secondRational.getDenominator();
        return new Rational(n, d);
    }

    /** Multiply a rational number to this rational */
    public Rational multiply(Rational secondRational) {
        long n = numerator * secondRational.getNumerator();
        long d = denominator * secondRational.getDenominator();
        return new Rational(n, d);
    }

    /** Divide a rational number from this rational */
    public Rational divide(Rational secondRational) {
        long n = numerator * secondRational.getDenominator();
        long d = denominator * secondRational.numerator;
        return new Rational(n, d);
    }

    @Override
    public String toString() {
        if (denominator == 1)
            return numerator + "";
        else
            return numerator + "/" + denominator;
    }

    @Override // Override the equals method in the Object class
    public boolean equals(Object other) {
        if ((this.subtract((Rational)(other))).getNumerator() == 0)
            return true;
        else
            return false;
    }

    @Override // Implement the abstract intValue method in Number
    public int intValue() {
        return (int)doubleValue();
    }

    @Override // Implement the abstract floatValue method in Number
    public float floatValue() {
        return (float)doubleValue();
    }

    @Override // Implement the doubleValue method in Number
    public double doubleValue() {
        return numerator * 1.0 / denominator;
    }

    @Override // Implement the abstract longValue method in Number
    public long longValue() {
        return (long)doubleValue();
    }

    @Override // Implement the compareTo method in Comparable
    public int compareTo(Rational o) {
        if (this.subtract(o).getNumerator() > 0)
            return 1;
        else if (this.subtract(o).getNumerator() < 0)
            return -1;
        else
            return 0;
    }
}

Sample output:


Related Solutions

. Put the equation into the standard form of a parabola and find the vertex, focus,...
. Put the equation into the standard form of a parabola and find the vertex, focus, and directrix (needs to be an equation of a line). The standard form of a parabola can be found in Section 7.3 of the textbook. Answers must be exact values and not approximations. 4y2 + 2 = -x + 8y A. Standard form B.Vertex C.Focus D.Directrix
A. Write an equation of a parabola with the given vertex and focus: vertex(2,4) and focus...
A. Write an equation of a parabola with the given vertex and focus: vertex(2,4) and focus (2,5) B. Write an equation for the parabola with a vertex (-1,5) and directrix x=-15 ​
What is the standard form of the equation of the parabola with the focus (−1,3) and...
What is the standard form of the equation of the parabola with the focus (−1,3) and the directrix x=9? Select the correct answer below: a) (x+1)2=−12(y−6) b) (y−3)2=−20(x−4) c) (x−9)2=8(y−1) d)(y−3)2=20(x−4) please show work and what is the correct answer? thanks
identify the equation . If it is a parabola, give its vertex, focus, and directrix; if...
identify the equation . If it is a parabola, give its vertex, focus, and directrix; if an ellipse, give its centre, vertices, and foci ; if a hyperbola, give its centre, vertices, foci, and asymptotes. (x + 1)^2/4 - y^2/9−=1
Part A: Express the quadratic function in standard form (vertex form). ?(?) = 1 − 12?...
Part A: Express the quadratic function in standard form (vertex form). ?(?) = 1 − 12? − 4? 2 Part B: Find the quotient and remainder using synthetic division. ?^4 + 2?^3 − 10? all over ? − 3 Part C: A stone is thrown upward from the top of a building. Its height (in feet) above the ground after t seconds is given by the function ℎ(?) = −16?^2 + 96? + 48. a. What maximum height does the...
Use Java (Algebra: solve 2 x 2 linear equations) A linear equation can be solved using...
Use Java (Algebra: solve 2 x 2 linear equations) A linear equation can be solved using Cramer’s rule given in Programming Exercise 1.13. Write a program that prompts the user to enter a, b, c, d, e, and f and displays the result. If ad - bc is 0, report The equation has no solution. Sample Run 1 Enter a, b, c, d, e, f: 9.0 4.0 3.0 -5.0 -6.0 -21.0 x is -2.0 and y is 3.0 Sample Run...
Use a system of equations to find the parabola of the form y=ax^2+bx+c that goes through...
Use a system of equations to find the parabola of the form y=ax^2+bx+c that goes through the three given points. (2,-12)(-4,-60)(-3,-37)
Writing Equations of Lines Write the slope-intercept form of the equation of the line given the...
Writing Equations of Lines Write the slope-intercept form of the equation of the line given the slope and y-intercept. Slope = -5, y-intercept = -3 Write the slope-intercept form of the equation of the line given the slope and y-intercept. Slope = -1, y-intercept = 5 Write the slope-intercept form of the equation of the line. y – 5 = -10(x – 4) Write the slope-intercept form of the equation of the line. Write the slope-intercept form of the equation...
Chemical equations serve a variety of purposes, but the most general form of a chemical equation...
Chemical equations serve a variety of purposes, but the most general form of a chemical equation is reactants -> products. Most often, reactants and products are described by their chemical formula, possibly including a designation of state of matter. Contrary to a general chemical equation, a balanced chemical equation always uses molecular formulas and is amended by stoichiometric factors to assure conservation of mass and/or moles. Chemical equations represent chemical reactions, and chemical reactions can be classified according to two...
For the following, you can either provide a vector equation for the curve, or you can...
For the following, you can either provide a vector equation for the curve, or you can describe the curve in words with sufficient details. a) Describe a curve that has curvature zero. b) Describe a curve that has torsion zero. c) Describe a curve that has constant nonzero curvature. d) Describe a curve that has constant nonzero torsion. e) Describe a curve that has zero curvature and zero torsion.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT