Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8893553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:16:36+00:00 2026-06-14T23:16:36+00:00

package homework4; public class CreditCardNumber { private String issuerID = 000000; private String accountNum

  • 0
package homework4;

public class CreditCardNumber {
private String issuerID = "000000";
private String accountNum = "999999999";
private int checkDigit = 0;

public CreditCardNumber(String TempissuerID, String TempaccountNum)
{
    if(TempissuerID != null && TempaccountNum != null && TempissuerID.length() == 6 && TempaccountNum.length() == 9)
        if(Digits(TempissuerID) && Digits(TempaccountNum))
        {
            issuerID = TempissuerID;
            accountNum = TempaccountNum;
            calcCheckDigits();
        }

}

public boolean Digits(String temp1)
{
    String temp = "0123456789";
    int count = 0;
    for(int i = 0; i < temp1.length();i++)
        for(int j = 0; j < temp.length();j++)
            if(temp1.charAt(i) != temp.charAt(j))
            {
                count++;

            }
    if(count == temp1.length()){
        return true;
    }
    return false;
}

public CreditCardNumber(){}

public String getID()
{
    return issuerID;
}

public String getAccNum()
{
    return accountNum;
}

public int getDigits()
{
    return checkDigit;
}

private void calcCheckDigits()
{
    int sum;
    sum = checkSum();
    if((sum + checkDigit) % 10 != 0)    
    {
        checkDigit = sum - (sum % 10);
    }

}

public void CreateCred(String TempissuerID)
{
    if(TempissuerID != null && TempissuerID.length() ==6 && Digits(TempissuerID))
    {
        issuerID = TempissuerID;
    }
    else 
    {
        issuerID = "000000";
    }
    StringBuilder TempString = new StringBuilder();
    for(int i = 0; i < 9 ; i++)
    {
        TempString = TempString.append((Math.random()*(9-0+1)+0));
        System.out.printf("%d",TempString);
    }
    accountNum = TempString.toString();
    calcCheckDigits();
}

 private int checkSum()
 {       StringBuilder temp = new StringBuilder();
         int num;
         int sum =0;
         for(int i = 0 ; i <issuerID.length();i++)
         {
                 temp.append(issuerID.length());
                 for(int j = 0 ; j < accountNum.length(); j++)

                 temp.append(accountNum.length());
         }
         for(int k = 0 ; k < temp.length(); k +=2)
         {
                 num = temp.charAt(k) - '0';
                 num *=2;
                 if(num > 9)
                   num = 1 + (num % 10);
                 temp.setCharAt(k, (char) num);
         }
         for(int v = 0 ; v < temp.length(); v++)
         {
                 sum += temp.charAt(v) - '0';
         }

         return sum;
 }

 public String toString()
 {      
     return issuerID + accountNum + checkDigit;

 }
}

// in another file

package homework4;
import java.util.Scanner;
public class Prog4 {

public static void main(String[] args)
{   CreditCardNumber[] cred1;
    CreditCardNumber cred2 = getInput();
    Display(cred2);
    cred1 = getInputArray();
}

public static CreditCardNumber getInput() {
    String ID;
    String accNum;
    CreditCardNumber tempCred;      
    Scanner scanner = new Scanner(System.in);
    System.out.printf("Please enter issuer ID:");
    ID = scanner.next();
    System.out.printf("Please enter account number:");
    accNum = scanner.next();
    tempCred = new CreditCardNumber(ID, accNum);
    return tempCred;
}
public static void Display(CreditCardNumber cred2)
{

    System.out.printf("The complete number from your input:");
    System.out.println(cred2);
    return;

}

public static CreditCardNumber[] getInputArray()
{
    CreditCardNumber[] tempArray;
    String tempID;
    int size;
    Scanner scanner = new Scanner(System.in);
    System.out.printf("Please enter size of the aray:");
    size = scanner.nextInt();
    if(size < 1)
    {
        size = 1;
    }
    tempArray = new CreditCardNumber[size];
    System.out.printf("Please enter issuer ID:");
    tempID = scanner.next();
    for(int i = 0; i < size; i++)
    {

    }

    return tempArray;
}

}

hi i have a question on the getInput method in main, when i compile the code and run it the out put is

enter issuer ID:321321
Please enter account number:654654654
The complete number from your input:0000009999999990 

which is the default value for issuerId and acountNum from the CreditCardNumber class

but what i want is this output

Enter a credit card issuer number: 321321
Enter an account number: 654654654
The complete number from your input: 
3213 2165 4654 6549

with 4 space between each 4 character
why does my code output the default value instead of the user input value ?

can anyone show me whats wrong with the code or getinput() function?

thank in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:16:38+00:00Added an answer on June 14, 2026 at 11:16 pm

    i just debugged your code, your digit method is returning false for this particular input , which will fail the if condition in the constructor, thus it would still hold the default values.

    just use regex to check if the string passed is numeric.

    change your Digits method like below.

        public boolean Digits(String temp1)
        {
            if(temp1.matches("[0-9]+")){
                return true;
            }
            else {
                return false;
            }
    }
    

    change yout toString method like this:

     public String toString()
     {   String s="";   
         String str= issuerID + accountNum ;
    
         return str;
    
     }
    

    it gave me the output:

    Please enter issuer ID:321321
    Please enter account number:654654654
    The complete number from your input:321321654654654
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package pkgPeople; import java.io.Serializable; import java.text.DecimalFormat; public class Person implements Serializable{ private String name;
package abc; class DependencyDataCollection { private int sNo; private String sessionID; private int noOfDependency;
package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
package org.study.algos; public class Study { public static void main(String[] args) { A a
package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
package polynomial; /** * * @author Steven */ public class Polynomial { private float
package com.test01; public class test01 { public static void main(String[] args) { System.out.println(hi); }
package P1; public class Base { private void pri( ) { System.out.println(Base.pri()); } void
package homework4; import java.util.Scanner; public class Prog4 { static Scanner scanner = new Scanner(System.in);
package homework4; import java.util.Scanner; public class Prog4 { static Scanner scanner = new Scanner(System.in);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.