Java Print
Java Print
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;
}
BankAccount[] 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) {
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;
}
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;
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;
default:
return;
}
}
if (ch == 3) i+=1;
}
[Link]();
}
----------------model: [Link]----------------------
package [Link];
}
--------------------Service: Shop------------------------
package [Link];
import [Link];
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");
}
//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.
//iii. boolean updatePrice(String productId, double newPrice) — Updates the price of the product if it exists.
//boolean addProduct(Product product) — Adds a new product to the shop’s product array if space permits.
}
}
----------------CartItem Model----------------
package [Link];
public class CartItem {
private Product product;
private int quantity;
private double totalPrice;
package [Link];
import [Link];
import [Link];
public class Cart {
private CartItem[] items;
public Cart() {
items = new CartItem[5];
}
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
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;
default : i+=1;
break;
}
}
// [Link]([Link]());
}
}
import [Link];
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;
}
@Override
public String toString() {
return " [patientId=" + patientId + ", patientName=" + patientName + ", age=" + age + ", gender="
+ gender + ", ailment=" + ailment + ", admissiondate=" + admissiondate + "]" +"\n";
}
//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 addmitedpatients() {
// TODO Auto-generated constructor stub
patients=new ArrayList<>();
}
import [Link];
import [Link];
import [Link];
import [Link];
}
-----------------Service implementation-------------------------
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Patients[] patients ;
addmitedpatients adpatients;
public Hospitalserviceimp() {
// TODO Auto-generated constructor stub
adpatients = new addmitedpatients();
if ([Link]().equals(patientid)) {
[Link]().remove(patient);
return true;
}
}
throw new PatientnotfoundException("Patient not foumd");
}
-------------Exception-=------------------------------
package [Link];
Methods to implement:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [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 ;
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;
}
@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 Employeedata() {
// TODO Auto-generated constructor stub
employees = new HashMap<>();
}
-------------------Service interface------------------------
package [Link];
import [Link];
import [Link];
---------------Service implementation---------------------------
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
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];
@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];
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];
@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;
}
@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 Store() {
products=new ArrayList<>();
}
@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];
@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];
package [Link];
import [Link];
import [Link] icientqohException;
import [Link];
import [Link];
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link] icientqohException;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
}
@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 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;
}
package [Link];