2022-09-17 09:33:07 -05:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
< html >
< head >
< title > CheckIBSN_10.java< / title >
< meta http-equiv = "content-type" content = "text/html; charset=UTF-8" >
< style type = "text/css" >
<!--
2022-09-22 13:02:22 -05:00
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
table {color: #888888; background-color: #313335; font-family: monospace}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
2022-09-17 09:33:07 -05:00
.comment {color: #808080}
.whitespace {color: #505050}
2022-09-22 13:02:22 -05:00
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
.string {color: #6a8759}
.number {color: #6897bb}
.ST0 {color: #287bde}
.literal {color: #cc7832}
2022-09-17 09:33:07 -05:00
-->
< / style >
< / head >
< body >
2022-09-22 13:02:22 -05:00
< table width = "100%" > < tr > < td align = "center" > /home/caleb/NetBeansProjects/ADSV Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/CheckIBSN_10.java< / td > < / tr > < / table >
2022-09-17 09:33:07 -05:00
< pre >
< span class = "comment" > /*< / span >
2022-09-22 13:02:22 -05:00
< span class = "comment" > * Click < / span > < span class = "ST0" > nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt< / span > < span class = "comment" > to change this license< / span >
< span class = "comment" > * Click < / span > < span class = "ST0" > nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java< / span > < span class = "comment" > to edit this template< / span >
2022-09-17 09:33:07 -05:00
< span class = "comment" > */< / span >
< span class = "literal" > package< / span > com.calebfontenot.mp2_calebfontenot;
< span class = "literal" > import< / span > java.util.*;
< span class = "comment" > /**< / span >
< span class = "comment" > *< / span >
2022-09-22 13:02:22 -05:00
< span class = "comment" > * < / span > < span class = "ST1" > @author< / span > < span class = "comment" > caleb< / span >
2022-09-17 09:33:07 -05:00
< span class = "comment" > */< / span >
< span class = "literal" > public< / span > < span class = "literal" > class< / span > CheckIBSN_10 {
2022-09-22 13:02:22 -05:00
< span class = "literal" > public< / span > < span class = "literal" > static< / span > < span class = "literal" > void< / span > < span class = "ST2" > main< / span > (String[] args)
2022-09-17 09:33:07 -05:00
{
< span class = "comment" > // Create scanner< / span >
2022-09-22 13:02:22 -05:00
Scanner input = < span class = "literal" > new< / span > Scanner(System.< span class = "ST3" > in< / span > );
2022-09-17 09:33:07 -05:00
< span class = "comment" > // define vars< / span >
< span class = "literal" > int< / span > digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9, inputISBN, outputISBN;
2022-09-22 13:02:22 -05:00
< span class = "literal" > boolean< / span > debug = < span class = "literal" > true< / span > ;
2022-09-17 09:33:07 -05:00
< span class = "comment" > // Scan individual numbers< / span >
2022-09-22 13:02:22 -05:00
System.< span class = "ST3" > out< / span > .print(< span class = "string" > " < / span > < span class = "string" > Enter the first 9 digits of an ISBN as an integer: < / span > < span class = "string" > " < / span > );
2022-09-17 09:33:07 -05:00
inputISBN = input.nextInt(); < span class = "comment" > // Get the first 9 digits of the ISBN< / span >
< span class = "comment" > // Divide the number up into 9 digits< / span >
digit1 = inputISBN / < span class = "number" > 100000000< / span > % < span class = "number" > 10< / span > ;
digit2 = inputISBN / < span class = "number" > 10000000< / span > % < span class = "number" > 10< / span > ;
digit3 = inputISBN / < span class = "number" > 1000000< / span > % < span class = "number" > 10< / span > ;
digit4 = inputISBN / < span class = "number" > 100000< / span > % < span class = "number" > 10< / span > ;
digit5 = inputISBN / < span class = "number" > 10000< / span > % < span class = "number" > 10< / span > ;
digit6 = inputISBN / < span class = "number" > 1000< / span > % < span class = "number" > 10< / span > ;
digit7 = inputISBN / < span class = "number" > 100< / span > % < span class = "number" > 10< / span > ;
digit8 = inputISBN / < span class = "number" > 10< / span > % < span class = "number" > 10< / span > ;
digit9 = inputISBN / < span class = "number" > 1< / span > % < span class = "number" > 10< / span > ;
< span class = "comment" > //System.out.println(digit1 +" " + digit2 +" " + digit3 +" " + digit4 +" " + digit5 +" " + digit1 +" " + );< / span >
< span class = "comment" > //Print digits for debugging< / span >
< span class = "literal" > if< / span > (debug == < span class = "literal" > true< / span > )
{
2022-09-22 13:02:22 -05:00
System.< span class = "ST3" > out< / span > .println(< span class = "string" > " < / span > < span class = "string" > inputISBN: < / span > < span class = "string" > " < / span > + inputISBN);
System.< span class = "ST3" > out< / span > .println(< span class = "string" > " < / span > < span class = "string" > ISBN split into 9 digits: < / span > < span class = "string" > " < / span > + (digit1) + < span class = "string" > " < / span > < span class = "string" > " < / span > + (digit2) + < span class = "string" > " < / span > < span class = "string" > " < / span > + (digit3) + < span class = "string" > " < / span > < span class = "string" > " < / span > + (digit4) + < span class = "string" > " < / span > < span class = "string" > " < / span > + (digit5) + < span class = "string" > " < / span > < span class = "string" > " < / span > + (digit6) + < span class = "string" > " < / span > < span class = "string" > " < / span > + (digit7) + < span class = "string" > " < / span > < span class = "string" > " < / span > + (digit8) + < span class = "string" > " < / span > < span class = "string" > " < / span > + (digit9));
2022-09-17 09:33:07 -05:00
}
< span class = "comment" > // Calculate!< / span >
outputISBN = ((digit1 * < span class = "number" > 1< / span > ) + (digit2 * < span class = "number" > 2< / span > ) + (digit3 * < span class = "number" > 3< / span > ) + (digit4 * < span class = "number" > 4< / span > ) + (digit5 * < span class = "number" > 5< / span > ) + (digit6 * < span class = "number" > 6< / span > ) + (digit7 * < span class = "number" > 7< / span > ) + (digit8 * < span class = "number" > 8< / span > ) + (digit9 * < span class = "number" > 9< / span > )) % < span class = "number" > 11< / span > ;
< span class = "comment" > //Output< / span >
< span class = "literal" > if< / span > (outputISBN == < span class = "number" > 10< / span > )
{
2022-09-22 13:02:22 -05:00
System.< span class = "ST3" > out< / span > .println(< span class = "string" > " < / span > < span class = "string" > The ISBN-10 number is < / span > < span class = "string" > " < / span > + digit1+digit2+digit3+digit4+digit5+digit6+digit7+digit8+digit9 + < span class = "string" > " < / span > < span class = "string" > X< / span > < span class = "string" > " < / span > );
2022-09-17 09:33:07 -05:00
}
< span class = "literal" > else< / span >
{
2022-09-22 13:02:22 -05:00
System.< span class = "ST3" > out< / span > .println(< span class = "string" > " < / span > < span class = "string" > The ISBN-10 number is < / span > < span class = "string" > " < / span > + digit1+digit2+digit3+digit4+digit5+digit6+digit7+digit8+digit9 + outputISBN);
2022-09-17 09:33:07 -05:00
}
}
}
< / pre > < / body >
< / html >