0% found this document useful (0 votes)
26 views11 pages

Project 45455

The document provides a Java implementation of a console application to manage merchandise data. It defines entity classes for customers and suppliers that extend an abstract merchandise class. A merchandise service class provides CRUD methods and validation. The main method implements a menu to add, view and search customer and supplier data using the service class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views11 pages

Project 45455

The document provides a Java implementation of a console application to manage merchandise data. It defines entity classes for customers and suppliers that extend an abstract merchandise class. A merchandise service class provides CRUD methods and validation. The main method implements a menu to add, view and search customer and supplier data using the service class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Certainly!

Below is a simple implementation of the described console


application in Java:

```java
package m.merchandise.entities;

public class Merchandise {


protected int partnerId;
protected String partnerName;
protected String city;
protected String state;

// Constructor
public Merchandise(int partnerId, String partnerName, String city,
String state) {
this.partnerId = partnerId;
this.partnerName = partnerName;
this.city = city;
this.state = state;
}

// Getters and Setters


public int getPartnerId() {
return partnerId;
}

public String getPartnerName() {


return partnerName;
}

public String getCity() {


return city;
}

public String getState() {


return state;
}
}
```

```java
package m.merchandise.entities;

public class Customer extends Merchandise {


private int creditLimit;
private String phoneNumber;
private String email;
// Constructor
public Customer(int partnerId, String partnerName, String city,
String state,
int creditLimit, String phoneNumber, String email) {
super(partnerId, partnerName, city, state);
this.creditLimit = creditLimit;
this.phoneNumber = phoneNumber;
this.email = email;
}

// Getters and Setters


public int getCreditLimit() {
return creditLimit;
}

public String getPhoneNumber() {


return phoneNumber;
}

public String getEmail() {


return email;
}
}
```
```java
package m.merchandise.entities;

public class Supplier extends Merchandise {


private double creditBalance;
private String adharNumber;

// Constructor
public Supplier(int partnerId, String partnerName, String city,
String state,
double creditBalance, String adharNumber) {
super(partnerId, partnerName, city, state);
this.creditBalance = creditBalance;
this.adharNumber = adharNumber;
}

// Getters and Setters


public double getCreditBalance() {
return creditBalance;
}

public String getAdharNumber() {


return adharNumber;
}
}
```

```java
package com.merchandise.services;

import java.util.ArrayList;
import java.util.List;

import m.merchandise.entities.Customer;
import m.merchandise.entities.Supplier;

public class MerchandiseService {


private List<Customer> customers;
private List<Supplier> suppliers;

public MerchandiseService() {
this.customers = new ArrayList<>();
this.suppliers = new ArrayList<>();
}

// Property Validation Methods


// Your validation methods go here...

// CRUD Operations

public void addCustomer(Customer customer) {


if (customers.size() < 5 && validateCustomer(customer)) {
customers.add(customer);
System.out.println("Customer added successfully!");
} else {
System.out.println("Failed to add customer. Validation failed or
maximum limit reached.");
}
}

public void addSupplier(Supplier supplier) {


if (suppliers.size() < 5 && validateSupplier(supplier)) {
suppliers.add(supplier);
System.out.println("Supplier added successfully!");
} else {
System.out.println("Failed to add supplier. Validation failed or
maximum limit reached.");
}
}
public void displayCustomerDetails() {
for (Customer customer : customers) {
System.out.println(customer.toString());
}
}

public void displaySupplierDetails() {


for (Supplier supplier : suppliers) {
System.out.println(supplier.toString());
}
}

public Customer getCustomerById(int customerId) {


for (Customer customer : customers) {
if (customer.getPartnerId() == customerId) {
return customer;
}
}
return null;
}

public List<Supplier> getAllSuppliers() {


return suppliers;
}
}
```

```java
package com.merchandise.consolepack;

import java.util.Scanner;

import com.merchandise.services.MerchandiseService;

public class MerchandiseConsoleApp {


public static void main(String[] args) {
MerchandiseService merchandiseService = new
MerchandiseService();
Scanner scanner = new Scanner(System.in);

while (true) {
System.out.println("Menu:");
System.out.println("a. Add Customer");
System.out.println("b. Add Supplier");
System.out.println("c. Display Report");
System.out.println("d. Search");
System.out.println("e. Exit");
System.out.print("Enter your choice: ");
String choice = scanner.next();

switch (choice.toLowerCase()) {
case "a":
// Add Customer
System.out.println("Enter Customer details:");
// Collect input and create Customer object
// Call merchandiseService.addCustomer(customer);
break;

case "b":
// Add Supplier
System.out.println("Enter Supplier details:");
// Collect input and create Supplier object
// Call merchandiseService.addSupplier(supplier);
break;

case "c":
// Display Report
System.out.println("Report:");
System.out.println("i. Customers - Display all Customer
Details");
System.out.println("ii. Suppliers - Display all Supplier
Details");
// Call respective methods from merchandiseService
break;

case "d":
// Search
System.out.println("Enter Customer ID to search:");
int customerId = scanner.nextInt();
// Call merchandiseService.getCustomerById(customerId);
// Display the details if found
break;

case "e":
// Exit
System.out.println("Exiting application...");
System.exit(0);
break;

default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}
```

Note: The validation methods for properties in `MerchandiseService`


are not implemented and need to be added based on the given
requirements. Additionally, you need to handle user input and create
objects accordingly in the main loop.

You might also like