A Java program has been started for you. The goal of the program is to prompt the user to enter a credit card number and then display whether the card is valid/invalid. Several method headers have already been defined in the code. Your task is to complete the body of each of these methods (6 in total) so that the program accomplishes the stated goal above.   Below I have started the code for you as practice and I even included hints as comments to help you out.    import java.util.Scanner; public class CreditCard {public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.print("Enter a credit card number: ");long number = input.nextLong(); if (isValid(number))System.out.println("valid");elseSystem.out.println("invalid");} /** Return true if the card number is validWhat makes a card number valid?1. 13-16 digits2. Prefix of 4, 5, 6, or 373. Result of Luhn check must be divisible by 10*/public static boolean isValid(long number) {// Enter your code here} /** Return sum of doubled even place digits in number */public static int sumOfDoubleEvenPlace(long number) {// Enter your code here} /** Return the input number if it is a single digit,otherwise, return the sum of the two digits For example, getDigit(4) = 4getDigit(18) = 9*/public static int getDigit(int number) {// Enter your code here} /** Return sum of odd place digits in number */public static int sumOfOddPlace(long number) {// Enter your code here} /** Return true if d is a prefix for number For example, prefixMatched(3784, 37) is trueprefixMatched(12345, 4) is false*/public static boolean prefixMatched(long number, int d) {return getPrefix(number, getSize(d)) == d;} /** Return the number of digits in d */public static int getSize(long d) {// Enter your code here} /** Return the first k number of digits from number. If the numberof digits in number is less than k, return number. */public static long getPrefix(long number, int k) {// Enter your code here}}

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

A Java program has been started for you. The goal of the program is to prompt the user to enter a credit card number and then display whether the card is valid/invalid. Several method headers have already been defined in the code. Your task is to complete the body of each of these methods (6 in total) so that the program accomplishes the stated goal above.

 

Below I have started the code for you as practice and I even included hints as comments to help you out. 

 

import java.util.Scanner;

public class CreditCard {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a credit card number: ");
long number = input.nextLong();

if (isValid(number))
System.out.println("valid");
else
System.out.println("invalid");
}


/** Return true if the card number is valid
What makes a card number valid?
1. 13-16 digits
2. Prefix of 4, 5, 6, or 37
3. Result of Luhn check must be divisible by 10*/
public static boolean isValid(long number) {
// Enter your code here
}


/** Return sum of doubled even place digits in number */
public static int sumOfDoubleEvenPlace(long number) {
// Enter your code here
}


/** Return the input number if it is a single digit,
otherwise, return the sum of the two digits

For example, getDigit(4) = 4
getDigit(18) = 9
*/
public static int getDigit(int number) {
// Enter your code here
}


/** Return sum of odd place digits in number */
public static int sumOfOddPlace(long number) {
// Enter your code here
}


/** Return true if d is a prefix for number

For example, prefixMatched(3784, 37) is true
prefixMatched(12345, 4) is false
*/
public static boolean prefixMatched(long number, int d) {
return getPrefix(number, getSize(d)) == d;
}


/** Return the number of digits in d */
public static int getSize(long d) {
// Enter your code here
}


/** Return the first k number of digits from number. If the number
of digits in number is less than k, return number. */
public static long getPrefix(long number, int k) {
// Enter your code here
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 7 steps with 7 images

Blurred answer
Knowledge Booster
Function Calling
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education