subject

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

thVkFu6 32

thVkFu6 is the number that should be converted into base 10 and 32 is the current base of thVkFu6.

thVkFu6 32
6b416C1bD23A 14
Ie7E0CHjgfej 22
DXBV8bON6L3KMoRM 34
2KiomlR4t0T7IO6 30
712d6Ab8 14
8231489531b759 12
5813045482d0b1 10
lJ3939oG06 25
6EhE85I73Da52fb 19
aE1GfIi42D1ck1GgC9H 21
4Lg9e34b9j 22
ebA 15
64KJdan8n05 27
25F48ccC4bCI2Jg91D48 20
64dCf5 18
101110100 2
113 5
aD5X57721 14
a4 15
1110 5
F5V 32
31LpjOb7 34
87 21
660174741073 8

//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();
}

}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 07:00
Why were most movies from the late 1890s until the early 1930s only filmed in black and white? there were only a few people who could afford the technology to produce color motion pictures back then. audiences did not want color motion pictures until later. the film used to make color motion pictures often overheated, which was a safety hazard, so it was generally not allowed. color films had to be hand-colored, frame by frame.
Answers: 3
question
Computers and Technology, 23.06.2019 16:50
15: 28read the summary of "an indian's view of indian affairs."15 betterin "an indian's view of indian affairs," it is asserted that conflicts could be reduced if white americansunderstood native americans..pswhich of the following would make this summary more complete? eleo the fact that chief joseph believes the great spirit sees everythinthe fact that chief joseph was born in oregon and is thirty-eight years oldo the fact that chief joseph states that he speaks from the hearthehehethe fact that chief joseph of the nez percé tribe made this claimebell- ==feetle===-felsefe ==submitmark this and retum.=
Answers: 3
question
Computers and Technology, 24.06.2019 14:00
In simple terms, how would you define a protocol?
Answers: 2
question
Computers and Technology, 24.06.2019 15:30
The idea that, for each pair of devices v and w, there’s a strict dichotomy between being “in range” or “out of range” is a simplified abstraction. more accurately, there’s a power decay function f (·) that specifies, for a pair of devices at distance δ, the signal strength f(δ) that they’ll be able to achieve on their wireless connection. (we’ll assume that f (δ) decreases with increasing δ.) we might want to build this into our notion of back-up sets as follows: among the k devices in the back-up set of v, there should be at least one that can be reached with very high signal strength, at least one other that can be reached with moderately high signal strength, and so forth. more concretely, we have values p1 ≥ p2 ≥ . . ≥ pk, so that if the back-up set for v consists of devices at distances d1≤d2≤≤dk,thenweshouldhavef(dj)≥pj foreachj. give an algorithm that determines whether it is possible to choose a back-up set for each device subject to this more detailed condition, still requiring that no device should appear in the back-up set of more than b other devices. again, the algorithm should output the back-up sets themselves, provided they can be found.\
Answers: 2
You know the right answer?
The provided data file contains entries in the form

ABCDE BB

That is - a v...
Questions
question
Mathematics, 11.10.2020 21:01
question
Mathematics, 11.10.2020 21:01
question
Mathematics, 11.10.2020 21:01
question
History, 11.10.2020 21:01
question
Mathematics, 11.10.2020 21:01
question
Mathematics, 11.10.2020 21:01
Questions on the website: 13722367