Question

package bigIntegerPackage; import java.util.Scanner; public class BigIntMathTesterOne {    private static Scanner keyboard = new Scanner(System.in);...


package bigIntegerPackage;

import java.util.Scanner;


public class BigIntMathTesterOne
{
   private static Scanner keyboard = new Scanner(System.in);

   /*

*
   * @param args
   */
   public static void main(String[] args)
   {
/**
* Sample valid input and resulting output
*    "44444444445555555555666666666677777777770000000000"
* stores ["4","4","4","4","4","4","4","4","4","4","5","5","5","5","5","5","5","5","5","5","6","6","6","6","6","6","6'<'6","6","6","7","7","7","7","7","7","7","7","7","7","0","0","0","0","0","0","0","0","0","0"] in ArrayList and sets the value to positive
*returns string "44444444445555555555666666666677777777770000000000"
* "100000" stores ["1","0","0","0","0","0"] in ArrayList and sets the value to positive
*returns string "100000"
*"+0" stores ["0"] in ArrayList and sets the value to positive
*returns string "0"
*"-0" stores ["0"] in ArrayList and sets the value to positive
*returns string "0"
*"-0023401" stores ["2","3","4","0","1"] in ArrayList and sets the value to negative
*returns string "-23401"
*-00100000 stores ["1","0","0","0","0","0"] in ArrayList and sets the value to negative
*returns string "-100000"
*Sample errors
*"5stt7" stores empty ArrayList, sets value to positive and returns string "empty"
*"+" stores empty ArrayList, sets value to positive and returns "empty"
*"-" stores empty ArrayList, sets value to positive and returns "empty"
*" 500" stores empty ArrayList, sets value to positive and returns "empty"
*
*/
       BigInt bigNumberOne = null;
       String yesNo = "no";
       String menuChoice = "q";
       BigInt bigNumberTwo = null;
       BigInt bigNumberAnswer = null;

       System.out.println("This program will perform basic math on large integer numbers");
       do
       {
           bigNumberOne = inputBigInteger();
           bigNumberTwo = inputBigInteger();
           System.out.println("You input the following integer numbers:\n" +
                   bigNumberOne + "\n" +
                   bigNumberTwo);
           System.out.println("You may perform one of the following opperations:");
           System.out.println("1. Add");
           System.out.println("2. Subtract the first number from the second number");
           System.out.println("3. Subtract the second number from the first number");
           System.out.println("4. Multiplication");
           System.out.println("5. Divide the first number by the second number");
           System.out.println("6. Divide the second number by the first number");
           System.out.println("7. Modulus the first number by the second number");
           System.out.println("8. Modulus the second number by the first number");
           System.out.println("9. Ignore numbers and start over");
           do
           {
               System.out.println("Please enter a menu choice number.");
               menuChoice = keyboard.nextLine();
           }while(!menuChoice.matches("([1-9])"));
           switch(menuChoice)
           {
           case "1":
               System.out.println("Adding " + bigNumberOne + " to " + bigNumberTwo);
               bigNumberAnswer = bigNumberOne.add(bigNumberTwo);
               break;
           case "2":
               System.out.println("Subtracting " + bigNumberOne + " from " + bigNumberTwo);
               bigNumberAnswer = bigNumberOne.subtract(bigNumberTwo);
               break;
           case "3":
               System.out.println("Subtracting " + bigNumberTwo + " from " + bigNumberOne);
               bigNumberAnswer = bigNumberOne.subtract(bigNumberTwo);
               break;
//           case "4":
//               System.out.println("Multiplying " + bigNumberOne + " by " + bigNumberTwo);
//               bigNumberAnswer = bigNumberTwo.multiply(bigNumberOne);
//               break;
//           case "5":
//               System.out.println("Dividing " + bigNumberOne + " by " + bigNumberTwo);
//               bigNumberAnswer = bigNumberOne.divide(bigNumberTwo);
//               break;
//           case "6":
//               System.out.println("Dividing " + bigNumberTwo + " by " + bigNumberOne);
//               bigNumberAnswer = bigNumberTwo.divide(bigNumberOne);
//               break;
//           case "7":
//               System.out.println("Modulus " + bigNumberOne + " by " + bigNumberTwo);
//               bigNumberAnswer = bigNumberOne.modulus(bigNumberTwo);
//               break;
//           case "8":
//               System.out.println("Modulus " + bigNumberTwo + " by " + bigNumberOne);
//               bigNumberAnswer = bigNumberTwo.modulus(bigNumberOne);
//               break;
           default:
               break;
           }
           System.out.println("Produces: " + bigNumberAnswer);
           System.out.println("Would you like to enter new numbers?");
           do
           {
               System.out.println("Please enter yes or no");
               yesNo = keyboard.nextLine();
              
           }while(!yesNo.equalsIgnoreCase("yes") && !yesNo.equalsIgnoreCase("no"));
       }while(yesNo.equalsIgnoreCase("yes"));

   }
  
   private static BigInt inputBigInteger()
   {
       BigInt newBigInt = null;
       String userIntInput = null;
       do
       {
           try
           {
               System.out.println("Please enter an integer of any size.");
               userIntInput = keyboard.nextLine();
               newBigInt = new BigInt(userIntInput);
           }
           catch(Exception myException)
           {
               System.out.println(myException.getMessage());
               newBigInt = null;
           }
       }while(newBigInt == null);
       return newBigInt;
   }

}

Using this driver class and in java language and

Add two public methods to the BigInt Class.

  • add(BigInt):BigInt
  • subtract(BigInt):BigInt

For each of these new public methods use private helper methods to solve the arithmetic.

The BigIntTesterAdditionAndSubtractionOutput document shows the terminal output of a correctly working BigInt class with its error handler.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

/*According to the requirements I have changed the given two class; Please find them below:*/

/*******************************/

import java.util.Scanner;

public class AlvaradoJLE71

{

private static Scanner input = new Scanner(System.in);

public static void main(String[] args)

{

Users myUser = new Users();

int size = myUser.arraySize(input);

String[] userNames =myUser.setUserNames(size, input);

String[] userIDs =myUser.setUserId(userNames, input);

myUser.printUserInfo(userNames, userIDs);

System.exit(0);

}// End Main.

}

/****************************************************/


/////Users Class:
import java.util.Scanner;
public class Users
{
private Scanner input = new Scanner(System.in);

//default constructor in the Users class
public void Users()
{

}

public int arraySize(Scanner inp)
{// This Method assigns a size to the array.
System.out.printf("%nHow many users? ");
int size = input.nextInt();//Getting input integer value as size
input.nextLine(); //Adding this line to move the cursor input section
return size;
}// End int arraySize.


public String[] setUserNames(int size, Scanner input)
{ // This method creates an array and stores user names.
String[] userNames = new String[size];
for (int i = 0; i < size; i++)
{
System.out.printf("%nEnter a name for user #%d: ",(i + 1));
userNames[i] =input.nextLine();
}
return userNames;
}// End String array setUserNames.


public String[] setUserId(String[] userName, Scanner input)
{ // This method creates an array and stores user IDs.
String[] userIds = new String[userName.length];
for (int i = 0; i < userName.length; i++)
{
System.out.printf("%nEnter user ID for %s ", userName[i]+": ");
userIds[i] = input.nextLine();
}
return userIds;
}// End String array setUserId

public void printUserInfo(String[] userName, String[] userId)
{
System.out.printf("%nUSER IDs & NAMES");
for (int i = 0; i < userName.length; i++)
{
System.out.printf("%n%nUser ID: %s", userId[i]);
System.out.printf("%nUser Name: %s", userName[i]);
}
}// End void printUserInfo.
}//End User Class

How many users? 5 Enter a name for user #1 : Alice Enter a name for user #2 : Bob Enter a name for user #3: Cammy Enter a nam

Add a comment
Know the answer?
Add Answer to:
package bigIntegerPackage; import java.util.Scanner; public class BigIntMathTesterOne {    private static Scanner keyboard = new Scanner(System.in);...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Evaluateeg EvaluateInFix.java: import java.util.Stack; import java.util.Scanner; public class EvaluateInfix {    public static void main(String[] args)...

    Evaluateeg EvaluateInFix.java: import java.util.Stack; import java.util.Scanner; public class EvaluateInfix {    public static void main(String[] args)    {    Scanner keyboard = new Scanner(System.in); System.out.println("This program an inFix Expression: "); System.out.print("Enter an inFix Expression that you want to evaluate (or enter ! to exit): "); String aString = keyboard.nextLine();    while (!aString.equals("!")) {    System.out.println (evaluateinFix(aString));    System.out.print("Enter an inFix Expression that you want to evaluate (or enter ! to exit): ");    aString = keyboard.nextLine(); } // end while...

  • public static void main(String[] args) { int option=0;    while(option<8){ Scanner input=new Scanner(System.in); System.out.println("Welcome! Please enter...

    public static void main(String[] args) { int option=0;    while(option<8){ Scanner input=new Scanner(System.in); System.out.println("Welcome! Please enter your name"); String name=input.next(); Person user= new Person(name); System.out.println("Your id: "+user.getID()); System.out.println("Login successful"); System.out.println("------------------------------"); while(option!=7){ System.out.println("1.Create and host a new meeting"); System.out.println("2.Cancel a meeting"); System.out.println("3.Attend an existing meeting"); System.out.println("4.Leave a meeting"); System.out.println("5.Display my meetings"); System.out.println("6.Display meetings organized by me"); System.out.println("7.Logout"); System.out.println("8.Exit the app");    option=input.nextInt(); switch(option){ case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break;...

  • package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private...

    package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...

  • This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static...

    This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static void main(String args[]) throws IOException { Scanner inFile = new Scanner(new File(args[0])); Scanner keyboard = new Scanner(System.in);    TwoDArray array = new TwoDArray(inFile); inFile.close(); int numRows = array.getNumRows(); int numCols = array.getNumCols(); int choice;    do { System.out.println(); System.out.println("\t1. Find the number of rows in the 2D array"); System.out.println("\t2. Find the number of columns in the 2D array"); System.out.println("\t3. Find the sum of elements...

  • Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent...

    Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent debugging * problems. Solve one at a time, uncommenting the next * one only after the previous problem is working correctly. */ public class FindTheErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); /* * Problem 1 Debugging * * This problem is to read in your first name, * last name, and current year and display them in *...

  • import java.util.Scanner; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in);...

    import java.util.Scanner; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); System.out.print("In:"); int nn = inp.nextInt(); int n0, n1, n2, n3, n4;    //Change only the code below //Set n0, n1, . . . n4 to each digits in nn by replacing //the blanks _A_, _B_, ect //Hint: the ones digit of 1234 is 1234%10 // the hundredth digit of 31415 is (31415/100)%10 n0 = _A_; n1 = _B_; n2 = _C_; n3 = _D_;...

  • Fix the following null pointer error. import java.util.*; import java.io.*; public class PhoneBook { public static...

    Fix the following null pointer error. import java.util.*; import java.io.*; public class PhoneBook { public static void main(String[]args)throws IOException { PhoneBook obj = new PhoneBook(); PhoneContact[]phBook = new PhoneContact[20]; Scanner in = new Scanner(System.in); obj.acceptPhoneContact(phBook,in); PrintWriter pw = new PrintWriter("out.txt"); obj.displayPhoneContacts(phBook,pw); pw.close(); } public void acceptPhoneContact(PhoneContact[]phBook, Scanner k) { //void function that takes in the parameters //phBook array and the scanner so the user can input the information //declaring these variables String fname = ""; String lname = ""; String...

  • departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE =...

    departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee;    } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...

  • Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender {...

    Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }    public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...

  • I need the following java code commented import java.util.Scanner; public class Main { public static void...

    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;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT