Case Study III

From CompSciWiki
Revision as of 20:22, 5 December 2007 by Mallory (Talk | contribs)

Jump to: navigation, search

COMP 1010 Home > Case Study III


Introduction

On your first day working at Funky Books Inc. you fixed some broken code (see Case Study I). Yesterday you modified the code for checking ISBNs to make the code more compact. You did this by using different kinds of loops (see Case Study II). The following Case Study will outline the events of your third day at Funky Books Inc. Today you will be modifying the same code, but this time you will be breaking the different tasks into methods.

This section will provide a real life problem that you will encounter on your third day working at Funky Books Inc.

   

{{{Body}}}

Code

import javax.swing.*; import java.util.Date;

public class ISBN {

     public static void main(String [] args)
     {
            String inputString; //used for JOP input
            int isbn;
            int sum = 0;  //must be initialized
            int digit;
            // Create a 10 "digit" ISBN given the first 9 "digits", and print the running totals

inputString = JOptionPane.showInputDialog ("Enter first 9 digits of ISBN"); System.out.println ("You entered the 9-digit ISBN: " + inputString); isbn = Integer.parseInt (inputString);

for (int i=9; i>0; i--)

            {

digit = isbn % 10; isbn = isbn / 10; sum = sum + digit * i; System.out.println ("Running total " + i + " * " + digit + " = " + sum); }//close for

System.out.println ("Weighted sum = " + sum);

if (sum%11 == 10) { System.out.println ("Check digit is 'X'"); System.out.println ("The 10 digit ISBN is " + inputString + 'X'); }//close if

            else
            {

System.out.println ("Check digit is " + sum%11); System.out.println ("The 10 digit ISBN is " + inputString + sum%11); }//close else

System.out.println ("\nDeveloped by COMP 1010 Instructor"); System.out.println ("Date: " + new Date()); System.out.println ("*** End of Processing ***");

     }//close main

}//close ISBN

Solution

Case Study III - Solution

Links To Other Case Studies

Case Study I: Day One at Funky Books Inc.
Case Study II: Day Two at Funky Books Inc.
Case Study IV: Day Four at Funky Books Inc.