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

import java.util.Scanner; public class challenge2{ public static void main(Strin

ID: 3814827 • Letter: I

Question

import java.util.Scanner;

public class challenge2{
public static void main(String[] args) { // main method
Scanner in = new Scanner(System.in);
int count = 0; // i is set to 0
long array[] = new long [16];
do
{
count =0;
array = new long [16];   
System.out.print("Enter your Credit Card Number : ");
long number = in.nextLong();
for(int i=0; number !=0; i++) {
array[i] = number % 10;
number = number /10;
count++;
}
}
while(count < 13); // number of digits in the card
if((array[count-1]==4) || (array[count-1] ==5) || (array[count-1] == 3 && array[count-2] == 7)){
if (isValid(array) == true) {
System.out.println(" The Credit Card Number is Valid. "); // card has to be divisble by 10
} else {   
System.out.println(" The Credit Card Number is Invalid. "); // if card is not divisible by 10 its invalid
}
}else{
System.out.println(" The Credit Card Number is Invalid. ");
}
}
public static boolean isValid(long[] array) { // Credit card is valid method
int total = sumOfDoubleEvenPlace(array) + sumOfOddPlace(array);
if ((total% 10 == 0)) {
for ( int i=0; i<array.length; i++){
System.out.println(array[i]);}
return true;
} else {
for (int i=0; i<array.length; i++){
System.out.println(array[i]);}
return false;
}
}
public static int getDigit(int number) {
if(number<=9) {
return number;
} else{
int firstDigit = number % 10;
int secondDigit = (int) (number / 10);
return firstDigit + secondDigit;
}
}
public static int sumOfOddPlace(long[] array) { //Result of any Odd divisble numbers
int result = 0;
for(int i=0; i<array.length; i++)
{
while (array[i] > 0) {
result += (int) (array[i] % 10);
array[i] = array[i] / 100;
}}
System.out.println(" The sum of the odd place is " + result);
return result;
}

public static int sumOfDoubleEvenPlace(long[] array) { // Even numbers divible by 10
int result = 0;
long temp = 0;
for(int i=0; i<array.length; i++) {
while (array[i]>0) {
temp = array[i] % 100;
result += getDigit ((int) (temp / 10) * 2);
array[i] = array[i] / 100;
}
}
System.out.print(" The sum of double even place is " + result);
return result;
}
}

My code is listed above ^ im having trouble tying it to Activity 2 as described in the paper and maybe some errors that might have (Java language)

Activity 2. [40 points] Method checkCustomers. Now you have a 2D array containing the customers' names and their respective card numbers. You have to use the method of Activity 1 to check whose card number is not valid. Each time you find a customer with an invalid card number, you have to write their information name and card number) in a file named Customers error. To complete this activity, you will have to implement two versions of this method: checkCustomersIter iterative version based on the use of loops) and checkCustomersRec (recursive version with no loop) For each of these methods, you have to: 1/ Write the pseudocode of it in the word document that you will submit along with the java file of this lab; and 2/ Implement it in the file challenge2.java and add relevant code in the main method to test it. Bonus Activity. [30 points] Method generateCCard. In this bonus activity, you have to design and implement a method called generateCCard, which generates valid credit card numbers. This method does not take any input and returns a 16-digit valid credit card number. This number should change at each execution of the method (i.e., the generation should be random, yet valid) If you choose to complete this bonus activity, you will have to 1/ Write the pseudocode of it in the word document that you will submit along with the java file of this lab; and 2/ Implement it in the file challenge2.java and add relevant code in the main method to test it.

Explanation / Answer

For the above problem, We have to follow the concept of modularity,

in order to do that, We have to create different classes

Create a project using any java development IDE like eclipse,netbeans and make below classes in that program to get the desired output.

1. We will create a class for customers which will include the details of the customer like name, address, and number.Just create a file name Costomer.java and paste the below code-

package console;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Collection;
public class Customer implements Serializable

{
HashMap <String,Card> cardList = new HashMap <String,Card>();
private String name;
private String address;
private String number;
private static final long serialVersionUID = 1L;
  
public Customer()
{
   this("","","");
}
  
  
public Customer(String name, String address, String number)
{
   super();
   this.name = name;
   this.address = address;
   this.number = number;
}
public String getName()
{
   return name;
}
public void setName(String name)
{
   this.name = name;
}
public String getAddress()
{
   return address;
}
public void setAddress(String address)
{
   this.address = address;
}
public String getNumber()
{
   return number;
}
public void setNumber(String number)
{
   this.number = number;
}

@Override
public String toString()
{
   return String.format("%s-15%s-15%s-15%s",this.name,this.address,this.number);
}

@Override
public boolean equals(Object obj)
{
   if (this == obj)
       return true;
   if (obj == null)
       return false;
   if (getClass() != obj.getClass())
       return false;
   Customer other = (Customer) obj;
   if (name == null)
   {
       if (other.name != null)
           return false;
   } else if (!name.equals(other.name))
       return false;
   return true;
}
Collection<Card> getCardList()
{
   return this.cardList.values();
  
}
   Card getCard(String number)
   {
       return this.cardList.get(number);
      
   }
   void newCard(Card card)
   {
       this.cardList.put(card.getNumber(), card);
      
   }
  
}

2. After doing that, it's time for us to make a class for card details. Create a class with name Card.java and paste the below code-

package console;
import java.io.Serializable;

public class Card implements Serializable
{
private String company;
private String expiry;
private String number;
private static final long serialVersionUID = 1L;

public Card()
{
   this("","","");
}
  
   public Card(String company, String expiry, String number)
{
   super();
   this.company = company;
   this.expiry = expiry;
   this.number = number;
}

   public String getCompany()
{
   return company;
}

public void setCompany(String company)
{
   this.company = company;
}


public String getExpiry()
{
   return expiry;
}


public void setExpiry(String expiry)
{
   this.expiry = expiry;
}


public String getNumber()
{
   return number;
}


public void setNumber(String number)
{
   this.number = number;
}

@Override
public String toString()
{
   return String.format("%s-15%s-15%s-15%s",this.company,this.expiry,this.number);
}


@Override
public boolean equals(Object obj)
{
   if (this == obj)
       return true;
   if (obj == null)
       return false;
   if (getClass() != obj.getClass())
       return false;
   Card other = (Card) obj;
   if (number == null)
   {
       if (other.number != null)
           return false;
   } else if (!number.equals(other.number))
       return false;
   return true;
}

}

3.Now we have to create a main class, let's name it as Program.java.Paste the below code-

package console;
import java.util.Scanner;
import java.util.Collection;

public class Program
public static void acceptCustomerDetails(Customer customer)
{
   System.out.printf("ENTER A SWEET NAME : ");
   sc.nextLine();
   customer.setName(sc.nextLine());
     
   System.out.printf("ENTER A CUTE ADDRESS : ");
   customer.setAddress(sc.nextLine());
     
   System.out.printf("ENTER A LONG NUMBER : ");
   customer.setNumber(sc.nextLine());
     
}
public static void printCustomerDetails()
{
   for (Customer customer : ServiceStation.station.getCustList())
   {
       System.out.println("NAME : "+customer.getName());
       System.out.println("ADDRESS : "+customer.getAddress());
       System.out.println("NUMBER : "+customer.getNumber());
              
   }
     
}
   public static void acceptCardDetails(Card card)
   {
       System.out.println("ENTER THE COMPANY NAME : ");
       sc.nextLine();
       vehicle.setCompany(sc.nextLine());
         
       System.out.println("ENTER THE EXPIRY DATE : ");
       vehicle.setCompany(sc.nextLine());
         
       System.out.println("ENTER THE CARD NUMBER : ");
       vehicle.setNumber(sc.nextLine());
         
   }
public static void printCardDetails(Customer customer)
{
   for (Card card : customer.getCardList())
           {
       System.out.println("COMPANY : "+card.getCompany());
       System.out.println("EXPIRY : "+card.getExpiry());
       System.out.println("NAME : "+card.getNumber());
       }
  
}

  
   public static void main(String[] args)
       {   
           Customer customer = new Customer();
           Vehicle vehicle = new Vehicle();
  
               acceptCustomerDetails (customer);
               Program.station.newCustomer(customer);
       }

complile and run the program and you will get the required output.

i have only covered that much part of this quetion as chegg suggested me to do as it is quite lengthy question.