Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pearson com/ /courses/58 d73f 1512b55 AC9247-cb334fe8310bAfc1b A Pre-Calc HW 66

ID: 3796213 • Letter: P

Question

Pearson com/ /courses/58 d73f 1512b55 AC9247-cb334fe8310bAfc1b A Pre-Calc HW 66 (15 PEARSON "3 g (Business: check ISBN o An ISBN-10 national standard Book Number) consists of 10 digits: drdadsdudsded,dedod,a The last digit, do is a checksum, which is calculated from the other nine digits using the following formula: (d, x 1 d, x 2 d 3 d o x 8 do x 9) 96 11 If the checksum is 16, the last digit is denoted as X according to the ISBN-10 convention write a program that prompts the user to enter the first 9 digits and displays the 10-digit ISBN (including leading zeros). Your program should read the input as an integer. Here is a sample run: Sample Run for Exercise03 09 Enter input data for the program (Sample data provided below. You may modify it) 434539934 Show the sample output Using the Preceeding Input command java Exercisee3 09 Enter the first 9 digits of an ISBN as integer 434539934 The ISBN-10 number is 4345399343 command

Explanation / Answer

// Below is the working solution:

import java.util.Scanner;

public class Exercise03_09{

public static void main(String []args){
Scanner scanner = new Scanner(System.in);
  
System.out.print("Enter the first 9 digits of an ISBN as Integer: ");
int isbn = scanner.nextInt();
  
String temp = Integer.toString(isbn);
int[] newInt = new int[9];
  
int initValue = 9 - temp.length();
String finalISBN = "";
  
for(int i = 0; i < 9; i++) {
//Append 0 if the bit is empty
if(i < initValue) {
newInt[i] = 0;
finalISBN += "0";
}
//Else append the digit present at i-initValue position
else {
newInt[i] = temp.charAt(i - initValue) - '0';
finalISBN += Integer.toString(newInt[i]);
}
}
  
int checksum = 0;
//Calculate the checksum according to the formula
for(int i=0; i<9;i++) {
checksum += newInt[i]*(i+1);
}
  
//Append the final 10th digit based on the mod(checksum,11) value.
//If mod value is 10 then append x otherwise the digit.
finalISBN += checksum%11 == 10? 'x': Integer.toString(checksum%11);
  
System.out.println("The ISBN-10 number is " + finalISBN);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote