0% found this document useful (0 votes)
27 views29 pages

Java Print

The document describes a banking and product management system with classes for BankAccount, Service, Product, Shop, Cart, and Patients. It includes methods for managing bank accounts, handling product inventory, and managing patient records in a hospital setting. The main functionality includes account checks, deposits, withdrawals, product searches, and patient admissions and discharges.

Uploaded by

kamaltej60
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)
27 views29 pages

Java Print

The document describes a banking and product management system with classes for BankAccount, Service, Product, Shop, Cart, and Patients. It includes methods for managing bank accounts, handling product inventory, and managing patient records in a hospital setting. The main functionality includes account checks, deposits, withdrawals, product searches, and patient admissions and discharges.

Uploaded by

kamaltej60
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

Bank Account: auto id adding

public class BankAccount {


private String accountNo;
private String accountName;
private double balance;
private static int lastassigneddigit = 0;

public BankAccount() {
// TODO Auto-generated constructor stub

}
// public BankAccount(String accountNo,String accountName)
public BankAccount(String accountName) {
super();
lastassigneddigit += 1;
[Link] = [Link](lastassigneddigit);
[Link] = accountName;
[Link] = 1000;
}

----- service ---------


public class Service {

BankAccount[] bankaccount ;

public Service(BankAccount[] bankaccount) {


// TODO Auto-generated constructor stub
[Link] = bankaccount;
}

//1)BankAccount checkAccount(String accountNo) This checks whether the given account number is available in the array or [Link]
exists return true else return false.
public boolean checkAccount(String accno) {

for (int i=0; i<[Link];i++) {


if(bankaccount[i].getAccountNo().equals(accno)) {
return true;
}
}

return false;
}

//[Link] getBalance(String accountNo) Which returns the balance in an account for the given accountNo
public double getBalance(String accno) {
for (int i=0; i<[Link];i++) {
if(bankaccount[i].getAccountNo().equals(accno)) {
return bankaccount[i].getBalance();
}
}
return 0;
}
//iii. boolean deposit(String accountNo, double amount) Which deposits the given amount into the given account number after
verifying whether the given account is present in the array or not.
public boolean deposit(String accno, double amount) {
double currentbalance = getBalance(accno);
for (int i=0; i<[Link];i++) {
if(bankaccount[i].getAccountNo().equals(accno)) {
currentbalance = currentbalance + amount;
bankaccount[i].setBalance(currentbalance);
return true;
}
}
return false;
}

// [Link] withdraw(String accountNo, double amount)


public boolean withdraw(String accno, double amount) {
double currentbalance = getBalance(accno);
for (int i=0; i<[Link];i++) {
if(bankaccount[i].getAccountNo().equals(accno)) {
currentbalance = currentbalance - amount;
bankaccount[i].setBalance(currentbalance);
return true;
}
}
return false;
}

//[Link] transferMoney(String fromAccount,String toAccount, double amount)


public boolean transferMoney(String fromAccount,String toAccount, double amount) {
double fromAccountbalance = getBalance(fromAccount);
double toAccountbalance = getBalance(toAccount);
for (int i=0; i<[Link];i++) {
if(bankaccount[i].getAccountNo().equals(fromAccount)) {
fromAccountbalance = fromAccountbalance - amount;
bankaccount[i].setBalance(fromAccountbalance);
}

if(bankaccount[i].getAccountNo().equals(toAccount)) {
toAccountbalance = toAccountbalance + amount;
bankaccount[i].setBalance(toAccountbalance);
return true;

}
return false; } }

Product Management
+++++++++++++++++

Create a Product class with 3 data members: productId (String), productName, and price. Provide constructors, setters, and getters.
Overload the constructor to accept only productId and productName with a default price of 100.0.
Create a Shop class that contains an array of Product. Populate the array using setters. The Shop class should have the following methods:
i. Product findProduct(String productId) — Checks if a product exists by its ID; returns the product object if found, else null.
ii. double getPrice(String productId) — Returns the price of the product for the given product ID.
iii. boolean updatePrice(String productId, double newPrice) — Updates the price of the product if it exists.
iv. boolean addProduct(Product product) — Adds a new product to the shop’s product array if space permits.
--------------Main------------------
int i = 0;

while(i == 0) {
[Link]("Enter choice: 1. Shopping \[Link] in cart \[Link] ");
int ch = [Link]();
[Link]();

if(ch == 1) {
[Link](" ------------Shoping------------\n1. Find product \[Link] \[Link] \[Link]
\[Link]");
int ch1 = [Link]();
[Link]();

switch(ch1) {
case 1:
[Link]("Enter Productid to find product: ");
String showproduct = shop.findProduct([Link]());
[Link](showproduct);
break;

case 2: [Link]("Enter Productid to get price: ");


String productid = [Link]();
[Link]([Link](productid));
break;

case 3: [Link]("Enter Productid to updateprice: ");


String productid1 = [Link]();
[Link]("Enter Price to updateprice: ");
double price = [Link]();
[Link]([Link](productid1,price));
break;

case 4: [Link]("Enter Productid to addproduct: ");


String prid = [Link]();
[Link]("Enter Productname to addproduct: ");
String prname = [Link]();
[Link]([Link](new Product(prid,prname)));
break;

default:
return;
}
}

if(ch ==2) {
[Link](" ------------Carts------------\n1. AddItem \[Link] \[Link] \[Link]
\[Link]");
int ch2 = [Link]();

switch(ch2) {
case 1:
[Link]("Enter Product: ");
String prd1 = [Link]();
[Link]("Enter Quantity:");
int qyt = [Link]();
[Link]([Link](shop.findingpid(prd1), qyt));
break;

case 2: [Link]("Enter Productid to removeitem: ");


String productid1 = [Link]();
[Link]([Link](productid1));
break;

case 3: [Link]("TotalBill : ");


[Link]([Link]());
break;

case 4: [Link]("TotalBill : ");


[Link]([Link]());
break;

default:
return;
}
}

if (ch == 3) i+=1;
}
[Link]();
}

----------------model: [Link]----------------------
package [Link];

public class Product {


private String productId;
private String productName;
private double price;

public Product(String productid,String productName) {


[Link] = productid;
[Link] = productName;
[Link] = 100;
}

public String getProductId() {


return productId;
}

public void setProductId(String productId) {


[Link] = productId;
}

public String getProductName() {


return productName;
}

public void setProductName(String productName) {


[Link] = productName;
}

public double getPrice() {


return price;
}

public void setPrice(double price) {


[Link] = price;
}

}
--------------------Service: Shop------------------------
package [Link];

import [Link];

public class Shop {


private Product[] product;

public Shop() {
product = new Product[7];
// TODO Auto-generated constructor stub
product[0] = new Product("1","Pen");
product[1] = new Product("2","Pencil");
product[2] = new Product("3","ballPen");
product[3] = new Product("4","GelPen");
product[4] = new Product("5","BlackPen");
}

public Product findingpid(String prid) {


for(Product pr:product) {
if([Link]().equals(prid)) {
return pr;
}
}
return null;
}

//i. Product findProduct(String productId) — Checks if a product exists by its ID; returns the product object if found, else null.
public String findProduct(String productId) {
for(Product pr:product) {
if([Link]().equals(productId)) {
return([Link]()+" " +[Link]() + " " +[Link]());

} return("NULL");
}

//double getPrice(String productId) — Returns the price of the product for the given product ID.

public double getPrice(String productId) {


for(Product pr:product) {
if([Link]().equals(productId)) {
return [Link]();
}
}
return 0;
}

//iii. boolean updatePrice(String productId, double newPrice) — Updates the price of the product if it exists.

public boolean updatePrice(String productId, double newPrice) {


double currentprice = getPrice(productId);
for(Product pr:product) {
if([Link]().equals(productId)) {
currentprice = newPrice;
return true;
}
}
return false;
}

//boolean addProduct(Product product) — Adds a new product to the shop’s product array if space permits.

public boolean addProduct(Product productss) {


for(int i=0;i<[Link];i++) {
if(product[i] == null) {
product[i] = productss;
return true;
}
}
return false;

}
}
----------------CartItem Model----------------
package [Link];
public class CartItem {
private Product product;
private int quantity;
private double totalPrice;

public CartItem(Product product, int quantity) {


[Link] = product;
[Link] = quantity;
[Link] = [Link]() * quantity;
}

public Product getProduct() {


return product;
}

public int getQuantity() {


return quantity;
}

public double getTotalPrice() {


return totalPrice;
}

public void increaseQuantity(int q) {


[Link] += q;
[Link] = [Link]() * [Link];
}
}

----------------- Service: Cartservice-----------------

package [Link];
import [Link];
import [Link];
public class Cart {
private CartItem[] items;

public Cart() {
items = new CartItem[5];
}

public boolean addItem(Product product, int quantity) {


if (product == null || quantity <= 0)
return false;

for (int i = 0; i < [Link]; i++) {


if (items[i] != null &&
items[i].getProduct().getProductId().equals([Link]())) {
items[i].increaseQuantity(quantity);
return true;
}
}

for (int i = 0; i < [Link]; i++) {


if (items[i] == null) {
items[i] = new CartItem(product, quantity);
return true;
}
}
return false;
}

public boolean removeItem(Product id) {


for (int i = 0; i < [Link]; i++) {
if (items[i] != null &&
items[i].getProduct().getProductId().equals([Link]())) {
items[i] = null;
return true;
}
}
return false;
}

public double calculateTotal() {


double total = 0;
for (CartItem item : items) {
if (item != null) {
total += [Link]();
}
}
return total;
}

public boolean checkout() {


double total = calculateTotal();
[Link]("Total Bill = " + total);

for (int i = 0; i < [Link]; i++) {


items[i] = null;
}
return true;
}
}

[Link] Management Domain Exercise Question


Create a Patient class with the following data members:
patientId (String)
patientName (String)
age (int)
gender (String)
ailment (String)
admissionDate ( LocalDate)
Provide constructors (full and partial as needed), getters, and setters.
Create a Hospital class with the following data members and methods:
List<Patient> patients — To store all admitted patients
Methods to implement:
void admitPatient(Patient patient) — Adds a patient to the list
boolean dischargePatient(String patientId) — Removes a patient from the list
int getTotalPatients() — Returns total admitted patients.
List<Patient> getPatientsByAgeRange(int minAge, int maxAge) — Returns patients whose age falls between minAge and maxAge.
Map<String, Integer> getCountByGender() — Returns a map with gender as key and count of patients as value.
FOLDER: MAIN, MODEL, SERVICE, SERVICEIMP, EXCEPTION
-------------- Main ------------------
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];

public class Main {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner([Link]);
Hospitalserviceimp hosp = new Hospitalserviceimp();

int i = 0;
while(i==0) {
String ch = "";
[Link]("Enter Choice \[Link] \[Link] "
+ "\[Link] \[Link] by age \[Link] \[Link]
by age \[Link]");
ch = [Link]();
switch(ch) {
case "1": [Link](new Patients("005","Sham",26,"Male","Cold",[Link](2024, 04, 23)));
break;

case "2": // Try Catch


try {
[Link]("006");
}
catch(PatientnotfoundException e) {
[Link]([Link]());
}
break;

case "3": [Link]("TotalPatients: " + [Link]());


break;

case "4": List<Patients> res = [Link](20, 25);


for(Patients pa:res) {
[Link]("Patients: " +pa);
}
break;

case "5": Map <String , Integer> gendercount = [Link]();


[Link]("Gendercount: " +gendercount);
break;

case "6": [Link]("Sorted Patients using comparable");


List<Patients> patients = [Link]();
[Link](patients);
for(Patients p:patients) {
[Link](p);
}

default : i+=1;
break;
}

}
// [Link]([Link]());
}
}

------------------------------Model : Paitents ----------------------------


package [Link];

import [Link];

public class Patients implements Comparable<Patients>{


private String patientId;
private String patientName;
private int age;
private String gender;
private String ailment;
private LocalDate admissiondate;

public Patients() {
// TODO Auto-generated constructor stub
}

public Patients(String patientId, String patientName, int age, String gender, String ailment,
LocalDate admissiondate) {
super();
[Link] = patientId;
[Link] = patientName;
[Link] = age;
[Link] = gender;
[Link] = ailment;
[Link] = admissiondate;
}

public String getPatientId() {


return patientId;
}

public void setPatientId(String patientId) {


[Link] = patientId;
}

public String getPatientName() {


return patientName;
}

public void setPatientName(String patientName) {


[Link] = patientName;
}

public int getAge() {


return age;
}

public void setAge(int age) {


[Link] = age;
}
public String getGender() {
return gender;
}

public void setGender(String gender) {


[Link] = gender;
}

public String getAilment() {


return ailment;
}

public void setAilment(String ailment) {


[Link] = ailment;
}

public LocalDate getAdmissiondate() {


return admissiondate;
}

@Override
public String toString() {
return " [patientId=" + patientId + ", patientName=" + patientName + ", age=" + age + ", gender="
+ gender + ", ailment=" + ailment + ", admissiondate=" + admissiondate + "]" +"\n";
}

public void setAdmissiondate(LocalDate admissiondate) {


[Link] = admissiondate;
}

//Comparable
public int compareTo(Patients p) {
return [Link]([Link], [Link]());
// return new Double([Link]).compareTo(new Double([Link]()));
}
}
------------model: addmitedpatient------------------
package [Link];

import [Link];
import [Link];

public class addmitedpatients {

private List<Patients> patients;

public addmitedpatients() {
// TODO Auto-generated constructor stub
patients=new ArrayList<>();
}

public addmitedpatients(List<Patients> patients) {


super();
[Link] = patients;
}
public List<Patients> getPatients() {
return patients;
}

public void setPatients(List<Patients> patients) {


[Link] = patients;
}
}

--------------Service Interpahse ------------------


package [Link];

import [Link];
import [Link];

import [Link];
import [Link];

public interface Hospitalservice {

List <Patients> getAllpatients();


void admitPatient(Patients patient);
boolean dischargePatient(String patientId) throws PatientnotfoundException;
int getTotalPatients() throws PatientnotfoundException;
List<Patients> getPatientsByAgeRange(int minAge, int maxAge) throws PatientnotfoundException ;
Map<String, Integer> getCountByGender();

}
-----------------Service implementation-------------------------
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];

public class Hospitalserviceimp implements Hospitalservice {

Patients[] patients ;
addmitedpatients adpatients;

public Hospitalserviceimp() {
// TODO Auto-generated constructor stub
adpatients = new addmitedpatients();

patients = new Patients[]{new Patients("001","Ram",22,"Male","Notserious", [Link](2025, 4, 24)),


new Patients("002","Rama",28,"Female","Notserious", [Link](2024, 3, 12)),
new Patients("003","Sam",25,"Female","serious", [Link](2024, 7, 20)),
new Patients("004","Jam",20,"Male","Notserious", [Link](2023, 6, 24))};
[Link](new ArrayList<>([Link](patients)));
}

// private List<Patients> Arrays(List<Patients> asList) {


// // TODO Auto-generated method stub
// return [Link]();
// }
//

public List<Patients> getAllpatients() {


// TODO Auto-generated method stub
return [Link]();
}

public void admitPatient(Patients patient) {


[Link]().add(patient);
}

public boolean dischargePatient(String patientid) throws PatientnotfoundException {


// TODO Auto-generated method stub
for (Patients patient:[Link]()) {

if ([Link]().equals(patientid)) {

[Link]().remove(patient);
return true;
}
}
throw new PatientnotfoundException("Patient not foumd");
}

public int getTotalPatients() {


// TODO Auto-generated method stub
return [Link]().size();
}

public List<Patients> getPatientsByAgeRange(int minAge, int maxAge) {


List <Patients> result = new ArrayList<>();
for (Patients patient : [Link]()) {
if([Link]() >= minAge && [Link]() <= maxAge) {
[Link](patient);
}
}
return result;
}

// Method to get patient count by gender


public Map<String, Integer> getCountByGender() {
Map<String, Integer> genderCount = new HashMap<>();
for (Patients patient : patients) {
[Link]([Link](), [Link]([Link](), 0) + 1);
}
return genderCount;
}
}

-------------Exception-=------------------------------
package [Link];

public class PatientnotfoundException extends Exception {

public PatientnotfoundException(String message) {


super(message);
}
}

Q) Map<String,Employee> employee;//store all employees

Methods to implement:

boolean addEmployee(Employee employee) — Adds an employee to the list

List<Employee> getEmployeesByDepartment(String department) — Returns employees in the department.

boolean removeEmployee(String employeeId) — Removes employee from list

int getTotalEmployees() — Returns total number of employees.

List<Employee> getEmployeesByPosition(String position) — Returns employees holding a specific position.

double getAverageSalaryByDepartment(String department) — Returns average salary for employees in a department.


FOLDER : MAIN, MODEL(2), SERVICE, SERVICEIMPL, COMPERATOR.
------------------main---------------------------
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class Main {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner([Link]);

EmployeeServiceImp empservice = new EmployeeServiceImp();


List<Employee> employee = [Link]();
// [Link](new Employee("003","Mam",23,"RD","SalesRep",80000,[Link](2025,10,23)));
// [Link]([Link]());
// [Link]([Link]("001"));
// [Link]([Link]());
// [Link]([Link]("RD"));
// [Link]([Link]("Manager"));
// [Link]([Link]("RD"));
// [Link]([Link]());

int i=0;

while(i==0) {
[Link]("Enter choice: \[Link] Employee \[Link] by dept \[Link] Employee \[Link]
Totalcount \[Link] \[Link] position \[Link]");
[Link]("[Link]");
int ch =0;
ch = [Link]([Link]());

switch(ch){
case 1: [Link]("Employee added: "
+[Link](new Employee("003","Mam",23,"RD","SalesRep",80000,[Link](2025,10,23))));
break ;

case 2: [Link]("Employees by dept: "+[Link]("RD"));


break;

case 3: [Link]("Remove Employee: "+[Link]("001"));


break;

case 4: [Link]("Employee totalcount: "+[Link]());


break;

case 5:[Link]("Employee avgSalary by dept: "+[Link]("RD"));


break;

case 6: [Link]("Employee by postion: "+[Link]("Manager"));


break;

case 7: [Link]("Name Comperator Class: ");


[Link](employee, new NameComperator());
for(Employee emp:employee) {
[Link](emp);
}
break;

default : i=1;
break;
}
}

----------------model: [Link]-----------------
package [Link];

import [Link];
public class Employee {
private String employeeId;
private String employeeName;
private int age;
private String department;
private String position;
private double Salary;
private LocalDate dateofJoining;

public Employee() {
// TODO Auto-generated constructor stub
}

public Employee(String employeeId, String employeeName, int age, String department, String position, double salary,
LocalDate dateofJoining) {
super();
[Link] = employeeId;
[Link] = employeeName;
[Link] = age;
[Link] = department;
[Link] = position;
Salary = salary;
[Link] = dateofJoining;
}

public String getEmployeeId() {


return employeeId;
}

public void setEmployeeId(String employeeId) {


[Link] = employeeId;
}

public String getEmployeeName() {


return employeeName;
}

public void setEmployeeName(String employeeName) {


[Link] = employeeName;
}

public int getAge() {


return age;
}

public void setAge(int age) {


[Link] = age;
}

public String getDepartment() {


return department;
}

public void setDepartment(String department) {


[Link] = department;
}

public String getPosition() {


return position;
}

public void setPosition(String position) {


[Link] = position;
}

public double getSalary() {


return Salary;
}

public void setSalary(double salary) {


Salary = salary;
}

public LocalDate getDateofJoining() {


return dateofJoining;
}

public void setDateofJoining(LocalDate dateofJoining) {


[Link] = dateofJoining;
}

@Override
public String toString() {
return "Employee [employeeId=" + employeeId + ", employeeName=" + employeeName + ", age=" + age
+ ", department=" + department + ", position=" + position + ", Salary=" + Salary + ", dateofJoining="
+ dateofJoining + "]";
}

-------------model: EMployeedata----------------
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class Employeedata {


private Map<String, Employee> employees ;

public Employeedata() {
// TODO Auto-generated constructor stub
employees = new HashMap<>();
}

public Employeedata(Map<String, Employee> employees) {


super();
[Link] = employees;
}

public Map<String, Employee> getEmployees() {


return employees;
}

public void setEmployees(Map<String, Employee> employees) {


[Link] = employees;
}

-------------------Service interface------------------------
package [Link];

import [Link];

import [Link];

public interface Employeeservice {

boolean addEmployee(Employee employee);


List<Employee> getEmployeesByDepartment(String department);
boolean removeEmployee(String employeeId);
int getTotalEmployees();
List<Employee> getEmployeesByPosition(String position);
double getAverageSalaryByDepartment(String department);

---------------Service implementation---------------------------
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

import [Link];
import [Link];
import [Link];

public class EmployeeServiceImp implements Employeeservice{


Employee[] employee;
Employeedata empdata;

public EmployeeServiceImp() {
// TODO Auto-generated constructor stub
empdata = new Employeedata();
[Link]().put("001",new Employee("001","Mam",23,"RD","Manager",80000,[Link](2025,10,23)));
[Link]().put("002",new Employee("002","Aam",23,"IT","Manager",80000,[Link](2025,10,23)));

}
// to get all employes
public Map<String, Employee> getAllEmployees(){
return [Link]();

}
// List of emp List<Employee>
public List<Employee> getListEmployees(){
List <Employee> listdata = new ArrayList<>();
for(String employeeid: [Link]().keySet()) {
Employee employee = [Link]().get(employeeid);
[Link](employee);
}
return listdata;
}

@Override
public boolean addEmployee(Employee employee) {
// TODO Auto-generated method stub
if(employee == null)
return false;

[Link]().put([Link](), employee);
return true;

}
@Override
public List<Employee> getEmployeesByDepartment(String department) {
// TODO Auto-generated method stub
List <Employee> empdept = new ArrayList<>();
for(String employeeid: [Link]().keySet()) {
Employee employee =[Link]().get(employeeid);
if([Link]().equals(department)) {
[Link](employee);
}

}return empdept;
}

@Override
public boolean removeEmployee(String employeeId) {
// TODO Auto-generated method stub
[Link]().remove(employeeId);
return true;
}

@Override
public int getTotalEmployees() {
return [Link]().size();
}

@Override
public List<Employee> getEmployeesByPosition(String position) {
List<Employee> result = new ArrayList();

for(String employeeId:[Link]().keySet()) {
Employee employee = [Link]().get(employeeId);

if([Link]().equals(position)) {
[Link](employee);
}
}
return result;
}

@Override
public double getAverageSalaryByDepartment(String department) {
// TODO Auto-generated method stub
double salary = 0;
for(Employee employee:[Link]().values()) {
salary += [Link]();
}
return salary/getTotalEmployees();
}

------------------comperator--------------------
package [Link];

import [Link];

import [Link];

public class NameComperator implements Comparator<Employee> {

@Override
public int compare(Employee o1, Employee o2) {
// TODO Auto-generated method stub
return [Link]().compareTo([Link]());
}

MAMCODE
Mam codes;
store management

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link] icientqohException;
import [Link];
import [Link];
import [Link];
import [Link];

public class Teststore {


public static void main(String[] args) {
StoreService sm=new StoreServiceImpl();

List<Product> products=[Link]();
[Link]("++++++++++List of product by price+++++++++");
[Link](products);

for(Product product:products) {
[Link](product);
}

[Link](products,new NameComparator());
[Link]("++++++++++List of product by name+++++++++");

for(Product product:products) {
[Link](product);
}

try {
if([Link]("P103")) {
[Link]("operation done");
}
else {
[Link]("operation failed");
}
} catch (Insu icientqohException e) {
// TODO Auto-generated catch block
[Link]();
} catch (ProductNotFoundException e) {
// TODO Auto-generated catch block
[Link]();
}

[Link]("operation done");
for(Product product:products) {
[Link](product);
}}}

package [Link];

import [Link];
import [Link];

public class Product implements Comparable<Product> {


private String id;
private String desc;
private double unitprice;
private int QOH;
private String category;
private LocalDate mfgDate;
private LocalDate expDate;
public Product() {

@Override
public int hashCode() {
return [Link](id);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != [Link]())
return false;
Product other = (Product) obj;
return [Link](id, [Link]);
}

@Override
public String toString() {
return "Product [id=" + id + ", desc=" + desc + ", unitprice=" + unitprice + ", QOH=" + QOH + ", category="
+ category + ", mfgDate=" + mfgDate + ", expDate=" + expDate + "]";
}

public Product(String id, String desc, double unitprice, int qOH, String category, LocalDate mfgDate,
LocalDate expDate) {
super();
[Link] = id;
[Link] = desc;
[Link] = unitprice;
QOH = qOH;
[Link] = category;
[Link] = mfgDate;
[Link] = expDate;
}

public String getId() {


return id;
}
public void setId(String id) {
[Link] = id;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
[Link] = desc;
}
public double getUnitprice() {
return unitprice;
}
public void setUnitprice(double unitprice) {
[Link] = unitprice;
}
public int getQOH() {
return QOH;
}
public void setQOH(int qOH) {
QOH = qOH;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
[Link] = category;
}
public LocalDate getMfgDate() {
return mfgDate;
}
public void setMfgDate(LocalDate mfgDate) {
[Link] = mfgDate;
}
public LocalDate getExpDate() {
return expDate;
}
public void setExpDate(LocalDate expDate) {
[Link] = expDate;
}

@Override
public int compareTo(Product o) {
// TODO Auto-generated method stub
return new Double([Link]).compareTo(new Double([Link]()));
}
}

package [Link];

import [Link];
import [Link];
import [Link];

public class Store {


private String id;
private String name;
private List<Product> products;

public Store() {
products=new ArrayList<>();
}

public Store(String id,String name) {


[Link]=id;
[Link]=name;
}
public String getId() {
return id;
}

public void setId(String id) {


[Link] = id;
}

public String getName() {


return name;
}

public void setName(String name) {


[Link] = name;
}

public List<Product> getProducts() {


return products;
}

public void setProducts(List<Product> products) {


[Link] = products;
}

@Override
public int hashCode() {
return [Link](id);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != [Link]())
return false;
Store other = (Store) obj;
return [Link](id, [Link]);
}
}

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class StoreInfo {


private String id;
private String name;
private Map<String,Product> products;
public StoreInfo() {
products=new HashMap<>();
}

public StoreInfo(String id,String name) {


[Link]=id;
[Link]=name;
}

public String getId() {


return id;
}

public void setId(String id) {


[Link] = id;
}

public String getName() {


return name;
}

public void setName(String name) {


[Link] = name;
}

public Map<String,Product> getProducts() {


return products;
}

public void setProducts(Map<String,Product> products) {


[Link] = products;
}

@Override
public int hashCode() {
return [Link](id);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != [Link]())
return false;
StoreInfo other = (StoreInfo) obj;
return [Link](id, [Link]);
}
}

package [Link];
import [Link];
import [Link];

public class NameComparator implements Comparator<Product> {


@Override
public int compare(Product o1, Product o2) {
// TODO Auto-generated method stub
return [Link]().compareTo([Link]());
}
}

package [Link];

import [Link];
import [Link] icientqohException;
import [Link];
import [Link];

public interface StoreService {


List<Product> getAllProducts();
boolean addProduct(Product product);
boolean removeProduct(String ProductId);
Product getProductById(String productId) throws ProductNotFoundException;
boolean sellItem(String productId) throws ProductNotFoundException,Insu icientqohException;
boolean purchaseItem(String productId) throws ProductNotFoundException;
}

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link] icientqohException;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class StoreMapSeviceImpl implements StoreService{

StoreInfo store;//declaring var


public StoreMapSeviceImpl() {
store=new StoreInfo();//initializing memory
[Link]("101");
[Link]("ABC");

[Link]().put("P101", new Product("P101","pen",20.0,25,"stationary",[Link](2023, 4,


14),[Link](2025, 4, 24)));
[Link]().put("P102", new Product("P102","pensil",10.0,0,"stationary",[Link](2023, 4,
14),[Link](2025, 4, 24)));
[Link]().put("P103", new Product("P103","eraser",15.0,25,"stationary",[Link](2023, 4,
14),[Link](2025, 4, 24)));
}
@Override
public List<Product> getAllProducts() {
// TODO Auto-generated method stub
return new ArrayList<>([Link]().values()) ;

}
@Override
public boolean addProduct(Product product) {
// TODO Auto-generated method stub
boolean flag=false;
[Link]().put([Link](),product);
if([Link]().get([Link]()).equals(product))
flag=true;
return flag;
}
@Override
public boolean removeProduct(String ProductId) {
// TODO Auto-generated method stub
[Link]().remove(ProductId);
return ![Link]().containsKey(ProductId);
}
@Override
public Product getProductById(String productId) throws ProductNotFoundException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean sellItem(String productId) throws ProductNotFoundException, Insu icientqohException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean purchaseItem(String productId) throws ProductNotFoundException {
// TODO Auto-generated method stub
return false;
}
}

package [Link];

import [Link];
import [Link];
import [Link];
import [Link] icientqohException;
import [Link];
import [Link];
import [Link];
import [Link];

public class StoreServiceImpl implements StoreService {


Product[] products;
Store store;//declaring var
public StoreServiceImpl() {
store=new Store();//initializing memory
[Link]("101");
[Link]("ABC");

products= new Product[]{new Product("P101","pen",20.0,25,"stationary",[Link](2023, 4, 14),[Link](2025, 4, 24)),


new Product("P102","pensil",10.0,0,"stationary",[Link](2023, 4, 14),[Link](2025, 4, 24)),
new Product("P103","eraser",15.0,25,"stationary",[Link](2023, 4, 14),[Link](2025, 4, 24))};
[Link]([Link](products));

}
public boolean sellItem(String productId) throws Insu icientqohException,ProductNotFoundException {
boolean flag=false;
Product product=[Link](productId);
if(product==null)
throw new ProductNotFoundException("Requested product not found");

if ([Link]()<=0)
throw new Insu icientqohException("Amount should not be zero");
else {
[Link]([Link]()-1);
flag= true;
}
return flag;
}

public boolean purchaseItem(String productId) throws ProductNotFoundException {


Product product=[Link](productId);
boolean flag=false;
if(product==null ) {
throw new ProductNotFoundException("Requested product not found");
}
else {
[Link]([Link]()+1);
flag= true;
}
return flag;
}

public Product getProductById(String productId) {


for (Product product:[Link]()) {
if([Link]().equals(productId))
return product;
}
return null;
}
@Override
public List<Product> getAllProducts() {
return [Link]();
}
@Override
public boolean addProduct(Product product) {
// TODO Auto-generated method stub
return [Link]().add(product);
}
@Override
public boolean removeProduct(String ProductId) {
// TODO Auto-generated method stub
//boolean flag=false;
Product product=[Link](ProductId);
if(product!=null)
return [Link]().remove(product);
return false;
}
}
package [Link];

public class Insu icientqohException extends Exception{


public Insu icientqohException() {
// TODO Auto-generated constructor stub
}
public Insu icientqohException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
}

package [Link];

public class ProductNotFoundException extends Exception {


public ProductNotFoundException() {
// TODO Auto-generated constructor stub
}
public ProductNotFoundException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
}

You might also like