Java programming:
The following java code is supposed to solve a linear equation of the form aX+b = 0
where a and b are real numbers. However, there are some errors, nd and x them using a
combination of exceptions and control statements. Hint. What could go wrong in the execution
of this program?
/*********************************************/
// here is the code I have:
import java.util.*;
public class Solver{
public static void main(String[] args){
System.out.println("Let us solve an equation of the form aX + b = 0 with a and
b real numbers.");
Scanner in = new Scanner(System.in);
System.out.println("Enter a:");
double a = in.nextDouble();
System.out.println("Enter a:");
double b = in.nextDouble();
double x = -b / a;
System.out.println("The solution to this equation is: " + x);
}
}
import java.util.*; public class Solver{ public static void main(String[] args){ System.out.println("Let us solve an equation of the form aX + b = 0 with a and b real numbers."); Scanner in = new Scanner(System.in); System.out.println("Enter a:"); double a = in.nextDouble(); System.out.println("Enter b:"); double b = in.nextDouble(); double x; if(a!=0) { x = -b / a; System.out.println("The solution to this equation is: " + x); } else System.out.println("Value of a should not be zero"); } }
Java programming: The following java code is supposed to solve a linear equation of the form...
Please, modify the code below to use the Switch Statements in Java instead of “if” statements to make the decisions. import java.util.Scanner; public class Area { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter code(C for circle, R for rectangle, S for square): "); char code = in.next().charAt(0); if(code == 'C') { System.out.print("Enter radius: "); double radius = in.nextDouble(); System.out.println("Area of circle is " + (Math.PI * radius * radius)); } else if(code == 'R') {...
Java Programming Question. I am writing a code to calculate the roots of the quadratic equation based on the values of the coefficients A, B, and C. I am supposed to enter 5 values for each coefficient, and the output should be five different answers (see example) using a for loop and if else statements. However, when I run my code, I am only able to enter one value for each coefficient and the output is one answer repeated five...
This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets and sets methods for the variables. Create a No-Arg constructor and a constructor that accepts all three values. At the end of the class add a main method that accepts variables from the user as input to represent the length and width of a room in feet and the price of carpeting per square foot in dollars...
I need the following java code commented import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner (System.in); int productNo=0; double product1; double product2; double product3; double product4; double product5; int quantity; double totalsales=0; while(productNo !=0) System.out.println("Enter Product Number 1-5"); productNo=input.nextInt(); System.out.println("Enter Quantity Sold"); quantity=input.nextInt(); switch (productNo) { case 1: product1=1.00; totalsales+=(1.00*quantity); break; case 2: product2=2.00; totalsales+=(2.00*quantity); break; case 3: product3=6.00; totalsales+=(6.00*quantity); break; case 4: product4=23.00; totalsales+=(23.00*quantity); break; case 5: product5=17.00; totalsales+=(17.00*quantity); break;...
Must be written in java. Modularize the following code. //CIS 183 Lab 4 //Joseph Yousef import java.util.*; public class SalaryCalc { public static void main(String [] args) { Scanner input = new Scanner(System.in); int sentinelValue = 1; //initializes sentinelValue value to 1 to be used in while loop while (sentinelValue == 1) { System.out.println("Enter 1 to enter employee, or enter 2 to end process: "); sentinelValue = input.nextInt(); input.nextLine(); System.out.println("enter employee name: "); String employeeName = input.nextLine(); System.out.println("enter day...
Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter as many student grades as you like. Enter a character to stop."); double grade = input.nextDouble(); double minGrade = Double.MAX_VALUE; double maxGrade = Double.MIN_VALUE; while (Character.isDigit(grade)) { if (grade == 0)...
Please explain if the following code is actually correct. If the following code correct, please explain why the code works and is also correct. Don’t use * Java’s Integer .toBinaryString(int) in this program./* According to the textbook and the instructor, I am not supposed to use arrays such as int binary[] = new int[25]; I guess this is the reason why this problem is starting to look kind of hard. Chapter 5 Exercise 37: Java Programming * * (Decimal to...
Here is the finsihed java program, it just needs to be converted to MIPs assembly language: import java.util.*; public class LoveCS { public static void main(String[] args) { int timesMessagePrinted; int count = 0; int sum = 0; Scanner input = new Scanner(System.in); System.out.print("How many times should the message be printed?: "); timesMessagePrinted = input.nextInt(); for(int x = 1; x <= timesMessagePrinted; x++) { System.out.println(x +" I love Computer Science!!"); count++; sum += x; } System.out.print("Printed this message " +count...
Please edit my following JAVA code so that there is no main function. I would like one function in this class that completes what the current program is trying to do so that I can call this class in my main class which will be separate. import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class enterwklyincme { private static DecimalFormat df = new DecimalFormat("0.00"); public static float readFloat(Scanner reader) { float num; while (true) { try { num = Float.parseFloat(reader.nextLine()); return...
Topic: Java Programming Hello, I have the following code attached below, and keep getting told that "Television" on the 23rd line "cannot be resolved to a type". It happens on this line of code... Television portable = new Television("Sharp", 19); Can you tell me how to fix this? Beginning of code... import java.util.Scanner; public class TelevisionDemo { {} public static void main(String[] args) { // //create a Scanner object to read from the keyboard Scanner keyboard = new Scanner(System.in); //...