Question

In: Computer Science

(code in java please) 14.20 (Check Protection) Computers are frequently employed in check-writing systems, such as...

(code in java please)

14.20 (Check Protection) Computers are frequently employed in check-writing systems, such as payroll and accounts payable applications. There are many strange stories about weekly paychecks being printed (by mistake) for amounts in excess of $1 million. Incorrect amounts are printed by computerized check-writing systems because of human error or machine failure. Systems designers build controls into their systems to prevent such erroneous checks from being issued.

Another serious problem is the intentional alteration of a check amount by someone who plans to cash a check fraudulently. To prevent a dollar amount from being altered, some computerized check-writing systems employ a technique called check protection. Checks designed for imprinting by computer contain a fixed number of spaces in which the computer may print an amount. Suppose a paycheck contains eight blank spaces in which the computer is supposed to print the amount of a weekly paycheck. If the amount is large, then all eight of the spaces will be filled. For example,

1,230.60 (check amount)
--------
12345678 (position numbers)

On the other hand, if the amount is less than $1000, then several of the spaces would ordinarily be left blank. For example,

   99.87
--------
12345678

contains three blank spaces. If a check is printed with blank spaces, it’s easier for someone to alter the amount. To prevent alteration, many check-writing systems insert leading asterisks to protect the amount as follows:

***99.87
--------
12345678

Write an application that inputs a dollar amount to be printed on a check, then prints the amount in check-protected format with leading asterisks if necessary. Assume that nine spaces are available for printing the amount.

Solutions

Expert Solution

import java.util.Scanner;

public class CheckProtection {

   public static void main(String[] args) {
       // Variable to hold the max number of spaces to be filled
       final int MAX_SPACES = 9;

       // String to prevent amount alteration on checks
       final String ALTERATION_PREVENTION_CHAR = "*";

       // Scanner to get user input
       Scanner in = new Scanner(System.in);

       // Get dollar amount
       System.out.print("Enter dollar amount to be printed: $");
       String amount = in.nextLine().trim();

       // Check if amount length is less than or equal to MAX_SPACES
       if (amount.length() <= MAX_SPACES) {
           // Convert amount to check protected format
           String amountInCheckProtectedFormat = String.format("%" + MAX_SPACES + "s", amount).replaceAll("\\s",
                   ALTERATION_PREVENTION_CHAR);

           // Print amount in check protected format
           System.out.printf("Amount in check protected format: %s", amountInCheckProtectedFormat);
       } else
           System.out.print("ERROR: Dollar amount cannot be greater than " + MAX_SPACES + " length.");
   }
}

CODE SCREENSHOTS:

SAMPLE OUTPUT:


Related Solutions

OPERATING SYSTEMS HOMEWORK: PLEASE CODE IN JAVA with comments & POST SCREENSHOTS OF OUTPUTS SCAN This...
OPERATING SYSTEMS HOMEWORK: PLEASE CODE IN JAVA with comments & POST SCREENSHOTS OF OUTPUTS SCAN This algorithm is performed by moving the R/W head back-and-forth to the innermost and outermost track. As it scans the tracks from end to end, it process all the requests found in the direction it is headed. This will ensure that all track requests, whether in the outermost, middle or innermost location, will be traversed by the access arm thereby finding all the requests. This...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ *...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ * This program takes a puzzle board and returns true if the * board is solvable and false otherwise * * Example: board 3 6 4 1 3 4 2 5 3 0 * The goal is to reach the 0. You can move the number of spaces of your * current position in either the positive / negative direction * Solution for this game...
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
Having a difficult time writing this code up. ( JAVA based ) Will Copy and paste...
Having a difficult time writing this code up. ( JAVA based ) Will Copy and paste the whole solution I was left with. Thank you in advance ! Lab 5 – Class Statistics Write a program which will uses the file Lab5Data.txt containing student names and the points they had earned at the end of the class. The program should use one or more arrays to create a report with the following information: -A table containing the student name, total...
Please write a Java algorithm solving the following problem: Implement a Java method to check if...
Please write a Java algorithm solving the following problem: Implement a Java method to check if a binary tree is balanced. For this assignment, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one. 1. First, please create the following two classes supporting the Binary Tree Node and the Binary Tree: public class BinTreeNode<T> { private T key; private Object satelliteData; private BinTreeNode<T> parent;...
This is an entry to Java Question. Please answer with Pseudocode and Java code for better...
This is an entry to Java Question. Please answer with Pseudocode and Java code for better understanding. We are mainly using basic in and out declarations and are focusing on API for method invocations. Any help would be very appreciated :) Problem 7: Distance (10 points) Use API (Data Science) Data Science is an emergent field from Computer Science with applications in almost every domain including finances, medical research, entertainment, retail, advertising, and insurance. The role of a data analyst...
This is for Java programming. Please use ( else if,) when writing the program) Write a...
This is for Java programming. Please use ( else if,) when writing the program) Write a java program to calculate the circumference for the triangle and the square shapes: The circumference for: Triangle = Side1 + Side2 +Sid3 Square = 4 X Side When the program executes, the user is to be presented with 2 choices. Choice 1 to calculate the circumference for the triangle Choice 2 to calculate the circumference for the square Based on the user's selection the...
This is an intro to java question. Please post with pseudocode and java code. Problem should...
This is an intro to java question. Please post with pseudocode and java code. Problem should be completed using repetition statements like while and selection statements. Geometry (10 points) Make API (API design) Java is an extensible language, which means you can expand the programming language with new functionality by adding new classes. You are tasked to implement a Geometry class for Java that includes the following API (Application Programming Interface): Geometry Method API: Modifier and Type Method and Description...
TEXT ONLY PLEASE ( PLEASE NO PDF OR WRITING) C++ CODE Instructions In a right triangle,...
TEXT ONLY PLEASE ( PLEASE NO PDF OR WRITING) C++ CODE Instructions In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle. If the triangle is a right triangle, output It is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT