018-002-003

Polymorphism Application: Order Processing System

Hard

Problem Description

polymorphism Application: Order Processing System

In this problem, you will create a program that designs a class hierarchy with per-type pricing logic (books and food) using polymorphism, processes an order list, and displays each item's information along with the total amount to standard output.

Learning Objective: Design extensible system utilizing polymorphism

Implement order system that calculates prices and processes based on different product types.

Input

Line 1: Number of items n
Following lines: Item type and details

  • book [price]
  • food [price] [days until expiry]

Output

Each item info and total

Item 1: [type] - [amount]
Item 2: [type] - [amount]
...
Total: [total]
```java

Food with 3 or fewer days gets 20% discount

## Example

Input:
```java
2
book 1000
food 500 2
```java
Output:
```java
Item 1: Book - 1000
Item 2: Food (Discounted) - 400
Total: 1400

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up