Question

Create a program that uses the methods in the String and Math classes to do the...

Create a program that uses the methods in the String and Math classes to do the following: ( complete in Javascript)

  • Ask the user to enter three integers for the values of A, B, and C in a quadratic equation.
  • Calculate and print the roots of the corresponding quadratic equation.

Homework Answers

Answer #1

Hi,

I have added the javascript code below. I you are statisfied with the solution kindly upvote me(I really in need of it). Good day.

Note: To run the code, open chrome browser, right click--> Inspect-->console--> paste this code--> hit enter--> give A,B and C values--> hit enter-->You can see the answer in console

Thanks

===================================code===========================

let rootOne, rootTwo;

// take input from the user

console.log("Hi Please enter the A,B and C value to construct a quadratic equation like: ax2 + bx + c = 0")
let a = prompt("Enter integer value for A: ");
let b = prompt("Enter integer value for B: ");
let c = prompt("Enter integer value for C: ");

// calculate discriminant
let discriminant = b * b - 4 * a * c;

// condition for real and different roots
if (discriminant > 0) {
rootOne = (-b + Math.sqrt(discriminant)) / (2 * a);
rootTwo = (-b - Math.sqrt(discriminant)) / (2 * a);

// result
console.log(`The roots of quadratic equation are ${rootOne} and ${rootTwo}`);
}

// condition for real and equal roots
else if (discriminant == 0) {
rootOne = rootTwo = -b / (2 * a);

// result

message = new String(`The roots of quadratic equation are ${rootOne} and ${rootTwo}`);

console.log(message);
}

// if roots are imagenary
else {
let realPartOfEq = (-b / (2 * a)).toFixed(2);
let imagPartOfEq = (Math.sqrt(-discriminant) / (2 * a)).toFixed(2);

message1 = new String( `The roots of quadratic equation are ${realPartOfEq} + ${imagPartOfEq}i and ${realPartOfEq} - ${imagPartOfEq}i`);

// result
console.log(message1);
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Create an interface to the keyboard (Scanner). Scanner is described in Chapter 2. 2) Prompt...
1) Create an interface to the keyboard (Scanner). Scanner is described in Chapter 2. 2) Prompt the user to enter their first and last name.. 3) Read the name into a String. 4) Print a person greeting such as “Hello FirstName LastName”. Print the users name in the greeting. 5) Prompt the user to enter 2 integers. 6) Read the integers into 2 variables into your program. 7) Prompt the user to enter a math operation – one of +,-,*,/...
3. Create a program which allows the user to swap individual words in an input string....
3. Create a program which allows the user to swap individual words in an input string. Given a string of input, your program should count and store the number of words in a 2D array. The user can then select the index of the words they want to swap. Your program should swap those two words and then print the entire string to ouput. • Use string prompt "> ". • Use indices prompt "Enter two indices: ". • Remove...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Draw a flowchart for this problem: Ask the user to enter two integers: int1 and int2....
Draw a flowchart for this problem: Ask the user to enter two integers: int1 and int2. The program uses the exponential operator to calculate and then print the result when int1 is raised to the int2 power. You also want to calculate the result when int1 is raised to the .5 power; however, you realize that it is not possible to take the square root of a negative number. If the value for int1 that is entered is a negative...
Create a program to calculate and print basic stats on a set of a given input...
Create a program to calculate and print basic stats on a set of a given input values representing students' scores on an quiz. 1) Ask the user for the total number of quiz scores to be input (assume a positive integer will be given). 2) Create an array to hold all the quiz scores and then get all the scores from input to put into the array. For example, if the user input 10 in step (1) then you should...
Python Practice Sample: Question 1. Math Write a program that runs these steps three times: ...
Python Practice Sample: Question 1. Math Write a program that runs these steps three times:  Ask the user to enter a non-zero number (can be positive or negative).  Find the cube of the number and subtracts 100.0 from the cube.  Calculate the square root of the result above. If the result is negative, multiply the result by -1 so it is positive before calculating the square root.  Print the result with two decimal places.
Create a program to ask the user for an integer number, positive only. If the number...
Create a program to ask the user for an integer number, positive only. If the number is between 0 and 255, printout the number in binary format to the screen. This will involve checking the bits, one by one, starting from the most significant place: 128. Use c++ 1. Modify the program to find the binary number, using a FOR loop, instead of the manual checking of each bit separately 2. What are the bitwise XOR and INVERSION operators? Find...
Create program that sorts words of a string based on first letter of each word. Use...
Create program that sorts words of a string based on first letter of each word. Use C programming language. - Only use stdio.h and string.h - Remove any newline \n from input string - Use insert function - Input prompt should say "Enter string of your choice: " - Output should print sorted string on new line Example:     Enter string of your choice: this is a string     a is string this
(C PROGRAMMING) Please use arrays// Create a program that presents a menu to the user to:...
(C PROGRAMMING) Please use arrays// Create a program that presents a menu to the user to: 1) enter data 2) print data 3) clear data 0) exit. Please complete option 3.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT