018-003-001

Generic Card Holder

Easy

Problem Description

In this problem, you will implement the displayInfo() method in the CardHolder class that returns a string in the format 'Card #[cardNumber]: [holderName]'.

Create a generic CardHolder class that can hold any type of card. It should have int cardNumber and String holderName fields, and a displayInfo() method that returns 'Card #[cardNumber]: [holderName]'.

Test Cases

※ Output examples follow programming industry standards

Input:
new CardHolder<>(12345, "Tanaka"); holder.displayInfo()
Expected Output:
Card #12345: Tanaka
Input:
new CardHolder<>(99, "Suzuki"); holder.displayInfo()
Expected Output:
Card #99: Suzuki
Input:
new CardHolder<>(1, "Test"); holder.displayInfo()
Expected Output:
Card #1: Test
Input:
new CardHolder<>(500, "Yamada"); holder.displayInfo()
Expected Output:
Card #500: Yamada
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 5 free executions remaining