The following program will compile and run, but it uses poor
Want to see the full answer?
Check out a sample textbook solutionChapter 1 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
C How to Program (8th Edition)
Starting Out With Visual Basic (7th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Java: Early Objects (6th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
- Below is a java program to find roots of quadratic equation. Please explain each line of code if what it does in the program when executed. Example: Java Program to Find Roots of a Quadratic Equation public class Main { public static void main(String[] args) { double a = 2.3, b = 4, c = 5.6; double root1, root2; double determinant = b * b - 4 * a * c; if (determinant > 0) { root1 = (-b + Math.sqrt(determinant)) / (2 * a); root2 = (-b - Math.sqrt(determinant)) / (2 * a); out.format("root1 = %.2f and root2 = %.2f", root1, root2); } else if (determinant == 0) { root1 = root2 = -b / (2 * a); out.format("root1 = root2 = %.2f;", root1); } else { double real = -b / (2 * a); double imaginary = Math.sqrt(-determinant) / (2 * a); out.format("root1 = %.2f+%.2fi", real, imaginary); out.format("\nroot2 = %.2f-%.2fi", real, imaginary); } } }arrow_forwardIn Java only please. The following progam uses a series to find the approximate value of pi. However, the statements are in the wrong order and there is also a bug in this program. Rearrange the statements and also fine and remove the bug so that this program can be used to approximate pi import java.util.*; public class Ch5_PrExercise2 { static Scanner console = new Scanner(System.in); public static void main(String[] args) { double pi = 0; long i ; long n; n = console.nextOnt(); System.out.print("Enter the value of n: "); System.out.println(); if(i % 2 == 0) pi = pi + (1 / (2 * i + 1)); else pi = pi - (1 / (2 * i + 1)); for(i = 0; i < n; i++) { pi = 0; pi = 4 * pi; } System.out.println("pi = " + [i); ) Note I know that the code go in the following order but not sure about the order of the if-else statement. n =System.out.print("Enter the value of n: "); console.nextInt(); System.out.println(); for(i = 0; i < n; i++) { pi = 0; pi = 4 * pi; for(i = 0; i < n; i++) {…arrow_forwardQuestion: (Code must be in java language) Assuming that you have the functions “drawPolygon(int[] x, int[] y, int n)” for drawing polygon, “drawRectangle(int x, int y, int width, int height)” for drawing rectangle and “drawCircle(int xc, intyc, int radius)” for drawing circle; draw the given shape. Where: R(300,250), T1(325,275), T2(475,275), T3(400,400), P1(285,250), P2(225,275), P3(200,450), P4(285, 300), Q1(515,250), Q2(575,275), Q3(600,450), Q4(515,300)//Look attached image here Note: No need to write the definition of the methods, there are no marks for definition. Only use method calls to create the shape as shown in Figure 1.arrow_forward
- Write java program that will calculate the amount to be paid for electrical consumption. This problem is to handle electric billing for customers. The billing is depending on the type of the customer account. There are two types of customers account; i) fixed rate method and 2) variable rate method in the case of fixed rate method. The minimum monthly charge of RM20.00 is assessed if the consumption is less than or equal 100 kwh( kilowatt-hours). Otherwise, the rate of RM 0.22 per kWh is charged for the first 100 kWh and the rate of RM 0.33 per kWh is charged for the additional consumption. In the case of variable rate method, the rate of RM 0.22 per kWh is charged for the consumption less than or equal to 100 kWh. Any additional consumption is charged at RM 0.35 per kWh.arrow_forward1 public static int sum(int x, int y){ 2 int z = x +y; 3 return z; 4 } 5 public static void main(String[] args){ 6 … 7 sum(a+2, b); 8 … 9 } write the signature of the method sum: sum(int,int) *Method name/parameter list list local variables of sum: x, y, and y are local variables of the function. list the parameters of sum: int x, int y write the line number where a call to sum occurs 7 list the arguments for the above call list the return type of sum here ______________arrow_forwardPROBLEM STATEMENT: Return the factorial of the provided integer parameter. public class FactorialComputation{public static int solution(int n){// ↓↓↓↓ your code goes here ↓↓↓↓return 0;} Can you please help me with the question above the Language is Java and can yiu use the java code that i gave above to answer the questionarrow_forward
- In Java please.Enter the code where it says " /* Your code goes here */ ". Suppose we add a fixed amount of money into our bank account at the beginning of every year. Modify the program from this section to show how many years it takes for the balance to double, given the annual contributions and the interest. import java.util.Scanner;/** This program computes the time required to double an investment with an annual contribution.*/public class DoubleInvestment{ public static void main(String[] args) { final double RATE = 5; final double INITIAL_BALANCE = 10000; final double TARGET = 2 * INITIAL_BALANCE; Scanner in = new Scanner(System.in); System.out.print("Annual contribution: "); double contribution = in.nextDouble(); double balance = INITIAL_BALANCE; int year = 0; // TODO: Add annual contribution, but not in year 0 /* Your code goes here */ System.out.println("Year: " + year); System.out.printf("Balance:…arrow_forwardUse the class provided, TestOverloadCall printMax to print the highest of 33 and 89Call printMax to print the highest of 55, 11, 99Submit, a print screen of the code and the output public class TestOverload {public static void main(String[] args) {//Call printMax to print the highest of 33 and 89//Call printMax to print the highest of 55, 11, 99}public static void printMax (int num1, int num2){if (num1 > num2)System.out.println("The highest is " + num1);elseSystem.out.println("The highest is " + num2);}//End of printMaxpublic static void printMax (int num1, int num2, int num3){if (num1 > num2 && num1 > num3)System.out.println("The highest is " + num1);else if (num2 > num1 && num2 > num3 )System.out.println("The highest is " + num2);elseSystem.out.println("The highest is " + num3);}//End of printMax}//End of TestOverloadarrow_forwardFix the mistakes in the following program so it runs as expected. There are 5 mistakes. All literals (such as 3.5) have the correct value and data type. // Java program by [Student name] [Today's date] public class Mistakes { public static void main(String[] args) { / This is a comment int z = 3.5; System.out.println("z is + z"); int s2 = "Michael"; System.out.println("s2 has the value " s2); } } Please show the mistakes clearly and how the change is made.arrow_forward
- The body mass index, BMI, is a measure used to determine if a person is overweight or not. We can calculate BMI from the weight of the person (in pounds) and the height (in inches) of the person.The formula for calculating BMI is:BMI = (weightInPounds * 703) divided by (heightInInches squared)In this problem, you will develop a Java program as a BMI calculator, that reads the user’s weight in pounds and height in inches, then calculates and displays the user’s body mass index BMI. Also, display the following information {from the US Department of Health} so the user can evaluate his/her BMI:BMI values:Underweight: less than 18.5Normal: between 18.5 and 24.9Overweight: between 25 and 29.9Obese: 30 or greaterarrow_forwardI keep coming up with the wrong answer, please help: Here is the code given: public class Billing {final static double TAX = 0.08;public static void main(String[] args) {final double HIGHPRICE = 24.99;final double MEDPRICE = 17.50;final double LOPRICE = 10.00;final int QUAN1 = 4;final int QUAN2 = 6;double bill;bill = computeBill(HIGHPRICE);System.out.println("The total for a photobook that costs $" +HIGHPRICE + " is $" + bill);bill = computeBill(MEDPRICE, QUAN1);System.out.println("The total for " + QUAN1 +" photobooks that cost $" +MEDPRICE + " is $" + bill);bill = computeBill(LOPRICE, QUAN2, 20.00);System.out.println("The total for " + QUAN2 +" photobooks that cost $" +LOPRICE + " with a $20 coupon is $" + bill);} public static double computeBill(double amt) {// Write your code here} public static double computeBill(double amt, int quantity) {// Write your code here}public static double computeBill(double amt, int quantity, double coupon) {// Write your code here}} Here is what they…arrow_forward**JAVA DEBUGGING** The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. public classDebugSeven3 { public static void main(String[] args) { String quote = "Honesty is the first chapter in the book of wisdom. - Thomas Jefferson"; System.out.println("index.of('f') is: " + quoteindexOf('f')); System.out.println("index.of('x') is: " + quoteindexOf('x')); System.out.println("char.At(5) is: " + quote.charAt(50)); System.out.println("endsWith(\"daughter\") is: " + quote.endsWith("daughter")); System.out.println("endsWith(\"son\") is: " + quote.endsWith("son")); System.out.println("replace('e', '*') is: ", quote.replace('e', '*')); } }arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education