Core Lab 2.12 [2 lab points) Create a class named BigFormula that will ask the u
ID: 3725193 • Letter: C
Question
Core Lab 2.12 [2 lab points) Create a class named BigFormula that will ask the user to enter three integers a, b, and c that can have any number of digits, and then compute and report the value of this formula: u=a+b(c-a) Note that you will have to use BigInteger stuff for this Lab, so (if you didn't do Lab 2.10) you'll need to look in the Java API for the Biginteger class to see how to do the various arithmetic operations, and you'll need to look in Scanner to find a method you can use to get a BigInteger from the keyboard. To get you started, to compute the BigInteger u = a + b you can just do v = a.add(b); where a and b are BigInteger variables. Here is a test case you can use on the original formula above: a? 1000 b? 9876 c? 123456789 value 1219249373164Explanation / Answer
solution:
import java.math.BigInteger;
import java.util.Scanner;
public class BigIntegerAdd {
public static void main(String[] args) {
// get user input
BigInteger v,v1,v2;
BigInteger a,b,c;
Scanner input = new Scanner(System.in);
//input three number
System.out.print("Enter the first number:");
a = input.nextBigInteger();
System.out.print("Enter the second value:");
b = input.nextBigInteger();
System.out.print("Enter the second value:");
c = input.nextBigInteger();
// get the sum of 2 BigInteger a and b
v = a.add(b);
//System.out.println("Sum of "+a+"+"+b+"="+v);
// get the subtract of 2 BigInteger c and a
v1 = c.subtract(a);
//System.out.println("Subtract of "+c+"-"+a+"="+v1);
// get the multiply of 2 BigInteger v1 and v2
v2 =v.multiply(v1);
System.out.println("a+b(c-a)");
System.out.println("Value="+v2);
System.out.println("b(c-a)");
BigInteger v3 = b.multiply(v1);
System.out.println("Value="+v3);
}
}
NOTE: v=a+b(c-a), so the solution for that equation is first add v=a+b , ans second v1=c-a, then get the value of a+b ans c-a then multiply the (a+b)*(c-a) to get the result and that result is store in v2 variable.
sample output:
Enter the first number:1000
Enter the second value:9876
Enter the second value:123456789
a+b(c-a)
Value=1342705161164
b(c-a)
Value=1219249372164
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.