Difference between revisions of "Case Study I"

From CompSciWiki
Jump to: navigation, search
(/*Edits (1) by Deanne)
Line 8: Line 8:
 
You arrive at your new desk to have the The Quality Assurance team of Funky Books Inc. request a program that allows a user to input the ISBN number of a book and validate the number. The code that was produced was such a mess that the employee was let go. Since you are the person to fill the newly available position, it only makes sense that you take over the project.
 
You arrive at your new desk to have the The Quality Assurance team of Funky Books Inc. request a program that allows a user to input the ISBN number of a book and validate the number. The code that was produced was such a mess that the employee was let go. Since you are the person to fill the newly available position, it only makes sense that you take over the project.
 
</p>
 
</p>
You are to complete the following tasks on the code below:
+
Complete the following tasks on the code below:
 
<ul>
 
<ul>
 
<li>Organize the code.</li>
 
<li>Organize the code.</li>

Revision as of 14:34, 30 November 2007

COMP 1010 Home > Java Fundamentals


Introduction

Today is your first day working for Funky Books Incorporated. You have been hired on as a Junior Software Developer with their Software Development Department. Your boss explains that you will be working with Java and assumes that you are familiar with Java code and the SDK. Being the exceptional employee that you are, you already took the time to go over the company coding standards for Java. It turns out that all the coding standards are the same as the COMP 1010 coding standards.

You arrive at your new desk to have the The Quality Assurance team of Funky Books Inc. request a program that allows a user to input the ISBN number of a book and validate the number. The code that was produced was such a mess that the employee was let go. Since you are the person to fill the newly available position, it only makes sense that you take over the project.

Complete the following tasks on the code below:

  • Organize the code.
  • Add comments to explain the code.
  • Optimize the code by removing unnecessary variables.
  • Find any errors in the code.
  • Add code to output progress reports as the program executes.

Remember to abide by the company coding standards while repairing the code.

   

{{{Body}}}



ISBN Check Digit Overview

The 10th digit of the ISBN number is the check digit. The check digit is calculated by multiplying the 9th digit of the ISBN by 9, the 8th digit of the ISBN by 8, etc. Then, these products are summed. Finally, the check digit is calculated by finding the remainder of the sum mod 11.

For example, the ISBN of the COMP 1010 textbook, “Starting Out With Java” is 0-321-47927-0. The user will input the first 9 digits: 032147927 The program will calculate the weighted value of the textbook’s ISBN:

7*9 + 2*8 + 9*7 + 7*6 + 4*5 +1*4 + 2*3 + 3*2 + 0*1 = 220

The program will use the modulus operator to divide the sum of 220 by 11 and find the remainder. In this example, the remainder is 0; so the check digit is 0:

220 % 11 = 0

Check out the back of the text: indeed, the 10th digit of the ISBN is 0!

Please note that if the check digit is ten, just output 10, even though the check digit should be only one digit long. In real life, an ISBN check digit of 10 is written as X. But for this program, just output 10. For example, try entering the first nine digits of the ISBN 0-7747-3776-X.

For more information on the ISBN check digits, please view Queen's University page on ISBN check digits.

Code

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

public class MessyCode_ISBN{

    public static void main (String [] args) {
        String temp = JOptionPane.showInputDialog("");int isbn = Temp;
        int digit1 = (isbn % 10);int total = digit1 * 9;isbn = isbn / 10;
        int digit2 = (isbn % 10);total = total + digit2 * 8;isbn = isbn / 10;
        int digit3 = (isbn % 10);total = total + digit3 * 7;isbn = isbn // 10;
        int digit4 = (isbn % 10) total = total + digit4 + 6;isbn = isbn / 10;
        int digit5 = (isbn / 10);total = total + digit5 * 5;isbN = isbn / 10;
        int digit6 = (isbn % 10);total = total + digit6 * 4;isbn = isbn / 10;
		int digit7 = (isbn % 10);total = total + digit7 * 3;isbn = isbn / 10;
		int digit8 = (isbn % 10);total = total + digit8 * 2;isbn = isbn / 10;
		int digit9 = (isbn * 10);total = total + digit9 - 1;isbn = isbn / 10;int checkDigit = total % 11;
        System.out.println ("The weighted total is: " + total +
                            "\nThe check digit is : " + checkDigit +
                            "\n\nThe 10-digit ISBN is: " + temp + checkDigit);

        System.out.println("\nProgrammed by Sloppy the Programmer");
        System.out.println("Date: " + new Date());
        System.out.println ("*** End of Processing ***");
        }
}

Solution

Case Study I - Solution

Resources

The resources needed to solve this case study can be found through the following links.

Internal Links

Chapter 1: Getting Started
Chapter 2: What is Programming?
Chapter 3: Java Fundamentals

External Links

COMP 1010 coding standards
ISBN Check Digit , Queen's University

Links To Other Case Studies

Case Study II: Day Two at Funky Books Inc.
Case Study III: Day Three at Funky Books Inc.
Case Study IV: Day Four at Funky Books Inc.