Question: Java programming How do i change this program to scan data from file and find the sum of the valid entry and count vaild and
Java programming How do i change this program to scan data from file and find the sum of the valid entry and count vaild and invalid entries The provided data file contains entries in the form ABCDE BB That is a value ABCDE, followed by the base BB Process this file, convert each to decimal base and determine the sum of the decimal base values. Reject any entry that is invalid. Report the sum of the values of the valid entries and total number of invalid entries datatxt file contains following as input First word is number and second is base, desired base is always ; for example thVkFu thVkFu is the number that should be converted into base and is the current base of thVkFu thVkFubCbDA IeECHjgfej DXBVbONLKMoRM KiomlRtTIOdAbbdb lJoGEhEIDafb aEGfIiDckGgCH Lgebj ebA KJdannFccCbCIJgDdCf aDX a FV LpjObThis is my program import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class BaseConversion public static boolean isValidIntegerString number, int base List Character occc new ArrayList Character ; for int i ; i && i base; i occc.addchar i; if base for int i ; i base ; i occc.addcharA i; for char c: number.toCharArray if occc.containsc return false; return true; private static int charValueInDecimalchar c if c && c return c ; return c A; private static char digitInCharint c if c && c return charc ; return charc A; public static String convertIntegerString firstValue, int firstBase, int finalBase BigInteger num BigInteger.ZERO; for char c: firstValue.toCharArray BigInteger x num.multiplynew BigIntegerStringvalueOffirstBase; num xaddnew BigIntegerStringvalueOfcharValueInDecimalc; String result ; BigInteger desired new BigIntegerStringvalueOffinalBase; while num.equalsBigIntegerZERO BigInteger remain num.moddesired; result digitInCharremainintValue result; num num.dividedesired; return result; public static void mainString args Scanner in new ScannerSystemin; System.out.printlnWelcome to Base Conversion program!"; System.out.println; System.out.printlnEnter the value to be converted: ; String number in nextLinetoUpperCase; System.out.printlnEnter the base of the entered value: ; int base Integer.parseInt in nextLine; int desiredBase ; Desired base is always if isValidIntegernumber base System.out.printlnInvalid number entered for base base; if base base System.out.printlnBase value base Must be in ; System.exit; System.out.printlnConverting number from base base to base desiredBase ; System.out.println; System.out.printlnconvertIntegernumber base, desiredBase; in close;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
