0% found this document useful (0 votes)
4 views3 pages

Java Assignment 5

The document outlines a Java assignment consisting of four questions focused on implementing generic programming concepts. It includes tasks for creating a flexible inventory system, a report generator, a financial calculator using bounded generics, and a payment processing system with subclasses for different payment types. Each question specifies requirements for class design, methods, and testing with various data types.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Java Assignment 5

The document outlines a Java assignment consisting of four questions focused on implementing generic programming concepts. It includes tasks for creating a flexible inventory system, a report generator, a financial calculator using bounded generics, and a payment processing system with subclasses for different payment types. Each question specifies requirements for class design, methods, and testing with various data types.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Assignment 5

Question 1: E-Commerce Inventory Container

An e-commerce company needs a flexible system to store different types of products (e.g., electronics,
clothing, books).

i
Task:​

ba
Design a generic class Inventory<T> to store product items.

Requirements:

um
●​ Store a single product of type T
●​ Provide methods to:
○​ Add product
○​ Retrieve product
●​ Create and test the class with:
○​ Electronics objects
M
○​ Clothing objects
●​ Display product details
AC

Question 2: Report Generator (Generic Method)

A business analytics system needs to generate reports for different types of data (sales, employee names,
product IDs).
-D

Task:​
Create a generic method to generate and display reports for any data type.

Requirements:
C

●​ Accept an array or list of any type


●​ Print all elements in a formatted way
●​ Test with:
○​ Sales figures (Integer/Double)
○​ Employee names (String)
○​ Product IDs (Integer)
Question 3: Financial Calculator (Bounded Generics)

A finance company needs a system to calculate totals from numerical datasets like transactions, salaries,
or profits.

Task:​
Implement a program using bounded generics.

Requirements:

i
ba
●​ Create a method that accepts only subclasses of Number
●​ Calculate:
○​ Sum
○​ Average

um
●​ Test with:
○​ Integer transactions
○​ Double salary data
M
Question 4: Payment Processing using Generics

A company is building a simple payment system that supports different payment types such as:
AC

●​ Credit Card
●​ UPI

The system should use Generics so that it can handle different payment types in a flexible way.
-D

1. Create Base Class

●​ Create a class Payment with:


○​ paymentId
C

○​ amount
●​ Add a method displayPayment()

2. Create Subclasses

●​ Create at least two subclasses:


○​ CreditCardPayment
○​ UPIPayment
●​ Each should override displayPayment()
3. Use ArrayList with Generics

●​ Create a separate ArrayList for:


○​ Credit card payments
○​ UPI payments
●​ Add at least 2–3 records in each list

4. Generic Method (Using Wildcard)

●​ Create a method that:


○​ Accepts a list of any type that extends Payment (? extends Payment)

i
○​ Traverses the list

ba
○​ Displays all payments

5. Execution

um
●​ Call the method for both lists
●​ Display all payment details M
AC
-D
C

You might also like