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 10) and determine the sum of the decimal (base 10) values. Reject any entry that is invalid. Report the sum of the values of the valid entries and total number of invalid entries //data.txt file contains following as input //First word is number and second is base, desired base is always 10; // for example thVkFu632 thVkFu6 is the number that should be converted into base 10 and 32 is the current base of thVkFu6. thVkFu6326b416C1bD23A 14 Ie7E0CHjgfej 22 DXBV8bON6L3KMoRM 342KiomlR4t0T7IO630712d6Ab8148231489531b759125813045482d0b110 lJ3939oG06256EhE85I73Da52fb 19 aE1GfIi42D1ck1GgC9H 214Lg9e34b9j 22 ebA 1564KJdan8n052725F48ccC4bCI2Jg91D482064dCf51810111010021135 aD5X5772114 a41511105 F5V 3231LpjOb73487216601747410738//This 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 isValidInteger(String number, int base){ List < Character > occc = new ArrayList < Character >(); for (int i =0; i <10 && i < base; i++){ occc.add((char)('0'+ i)); } if (base >=10){ for (int i =0; i <= base -10; i++){ occc.add((char)('A'+ i)); }} for (char c: number.toCharArray()){ if (!occc.contains(c)){ return false; }} return true; } private static int charValueInDecimal(char c){ if (c <='9' && c >='0'){ return c -'0'; } return c -'A'+10; } private static char digitInChar(int c){ if (c <=9 && c >=0){ return (char)(c +'0'); } return (char)((c -10)+'A'); } public static String convertInteger(String firstValue, int firstBase, int finalBase){ BigInteger num = BigInteger.ZERO; for (char c: firstValue.toCharArray()){ BigInteger x = num.multiply(new BigInteger(String.valueOf(firstBase))); num = x.add(new BigInteger(String.valueOf(charValueInDecimal(c)))); } String result =""; BigInteger desired = new BigInteger(String.valueOf(finalBase)); while (!num.equals(BigInteger.ZERO)){ BigInteger remain = num.mod(desired); result = digitInChar(remain.intValue())+ result; num = num.divide(desired); } return result; } public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println("Welcome to Base Conversion program!"); System.out.println(""); System.out.println("Enter the value to be converted: "); String number = in .nextLine().toUpperCase(); System.out.println("Enter the base of the entered value: "); int base = Integer.parseInt( in .nextLine()); int desiredBase =10; // Desired base is always 10 if (!isValidInteger(number, base)){ System.out.println("Invalid number entered for base "+ base); } if (base <2|| base >36){ System.out.println("Base value "+ base +" Must be in [2,36]"); System.exit(0); }} System.out.println("Converting "+ number +" from base "+ base +" to base "+ desiredBase +"..."); System.out.println(""); System.out.println(convertInteger(number, base, desiredBase)); in .close(); }}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!