Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class ProcessCardNumbers { /** * Write a main method to process a text fi

ID: 3622179 • Letter: P

Question

public class ProcessCardNumbers
{

/**
* Write a main method to process a text file of credit cards (cardNumbers.txt).
* The method should read each card number from the file, print the card number
* and whether or not the card is valid, invalid or and unknown card type.
* Use exception handing to catch FileNotFoundExceptions and IOExceptions.
*/
public static void main()
{

}

}







public class CreditCard
{
private String cardNumber;

/**
* Constructor for objects of class CreditCard.
*
* @param cardNumber A credit card number used to initialize the field
*
*/
public CreditCard(String cardNumber)
{

}

/**
* Accessor method to return the cardNumber
*
* @return A string that is the credit card number
*/
public String getCardNumber()
{
return cardNumber;
}

/**
* Mutator method to set the cardNumber
*
* @param cardNumber A credit card number
*/
public void setCardNumber(String cardNumber)
{

}


/**
* Using the leading digits and the length of the card number, this method
* determines if the card type is either "Visa", "MasterCard", "American Express", or "Discover"
* or an unknown card type.
*
* @return The credit card type, either "Visa", "MasterCard", "American Express", or "Discover"
* or the string "Unknown" if the type cannot be found.
*
*/
public String creditCardType()
{
return null;
}
/**
* Determins whether the number parameter is a single or double digit number.
* If it is a single digit number, return that number, otherwise
* return the sum of the two digits in the number parameter
*
* @param number A single or double digit integer
* @return An integer, either the single digit number parameter
* or the sum of the two digits of the double digit parameter
*/
public int getDigit(int number)
{

return 0;
}

/**
* This method returns the total of doubling every second digit from right to left.
* If doubling of a digit results in a two-digit
* number, add up the two digit to get a single digit number and add to the total.
*
* @return An integer which is the sum of the digits.
*/
public int sumEverySecondDigitRightToLeft()
{

return 0;
}

/**
* The method calculates the sum of the digits in the odd positions of the
* credit card string, going from right to left.
*
* @return An integer which is the sum of the digits.
*/
public int sumOfOddPlaceDigitsRightToLeft()
{

return 0;
}

/**
* The method determines if the credit card number is valid.
* If the card is valid, the total of sumEverySecondDigitRightToLeft()
* and sumOfOddPlaceDigitsRightToLeft()
* should be divisible by 10 with no remainder.
*
* @return A boolean value of true if the card number is valid,
* false, otherwise.
*/
public boolean isValid()
{

return true;
}


}

 

 

 

 

 

Explanation / Answer

 

This is the code for reading a file using Java. Change the variable according to you problem.

import java.io.*;
class FileRead 
{
   public static void main(String args[])
  {

      try{
    // Open the file that is the first 
    // command line parameter
    FileInputStream fstream = new FileInputStream("textfile.txt");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;

    //Read File Line By Line
    while ((strLine = br.readLine()) != null)   {
      // Print the content on the console
      System.out.println (strLine);
    }
    //Close the input stream
    in.close();
    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }
  }
}