Professional Documents
Culture Documents
import java.util.Scanner;
import java.io.*;
class Source{
public static void main(String args[])
{
}}
class Address implements Serializable{
String city;
String State;
int zip;
String Country;
public Address(String city, String state, int zip, String country) {
this.city = city;
State = state;
this.zip = zip;
Country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return State;
}
public void setState(String state) {
this.State = state;
}
int bookId;
String title;
String description;
String author;
int totalQuantity;
int availableQuantity;
double price;
double rentPerDay;
public Book(int bookId, String title, String description, String author, int
totalQuantity, int availableQuantity,
double price, double rentPerDay) {
this.bookId = bookId;
this.title = title;
this.description = description;
this.author = author;
this.totalQuantity = totalQuantity;
this.availableQuantity = availableQuantity;
this.price = price;
this.rentPerDay = rentPerDay;
}
public Book() {}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getTotalQuantity() {
return totalQuantity;
}
} else {
break;
}
}
ois.close();
} catch (IOException ioe2) {
System.out.println("IOException2");
}
return booksArray;
}
}
class Customer implements Serializable{
int userId;
String emailId;
String password;
String firstName;
String lastName;
String city;
String gender;
long phoneNumber;
Address address;
public Customer(int userId, String emailId, String password, String
firstName, String lastName, String city,
String gender, long phoneNumber, Address address) {
this.userId = userId;
this.emailId = emailId;
this.password = password;
this.firstName = firstName;
this.lastName = lastName;
this.city = city;
this.gender = gender;
this.phoneNumber = phoneNumber;
this.address = address;
}
@Override
public String toString() {
return "Customer [userId=" + userId + ", emailId=" + emailId + ",
password=" + password + ", firstName="
+ firstName + ", lastName=" + lastName + ", city=" + city +
", gender=" + gender + ", phoneNumber="
+ phoneNumber + ", address=" + address + "]";
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public long getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(long phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
interface CustomerService{
void writeCustomer();
Customer[] readCustomer();
void insertCustomer(Customer customer);
}
class CustomerServiceImpl implements CustomerService {
public static Customer[] customerArray = new Customer[5];
public static int count = 0;
File f2 = new File("customer.txt");
FileOutputStream fos = null;
FileInputStream fis = null;
ObjectOutputStream oos = null;
ObjectInputStream ois = null;
} else {
break;
}
}
ois.close();
} catch (IOException ioe4) {
System.out.println("IOException4");
}
return customerArray;
}
}
-----------------------------------------------------------------------------------
-
Sore BooksDetails to Collection:(L2-1)
import java.util.*;
import java.util.Map.Entry;
interface AdminService{
void addBooks(Book book);
void displayBooks();
}
class Source{
public static void main(String []args){
}
}
class Customer implements Comparable<Customer>{
int userId;
String emailId;
String password;
String firstName;
String lastName;
String city;
String gender;
long phoneNumber;
Address address;
public Customer(int userId, String emailId, String password, String
firstName, String lastName, String city,
String gender, long phoneNumber, Address address) {
this.userId = userId;
this.emailId = emailId;
this.password = password;
this.firstName = firstName;
this.lastName = lastName;
this.city = city;
this.gender = gender;
this.phoneNumber = phoneNumber;
this.address = address;
}
@Override
public String toString() {
return "Customer [userId=" + userId + ", emailId=" + emailId + ",
password=" + password + ", firstName="
+ firstName + ", lastName=" + lastName + ", city=" + city +
", gender=" + gender + ", phoneNumber="
+ phoneNumber + ", address=" + address + "]";
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public long getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(long phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
@Override
public int compareTo(Customer c){
return this.userId-c.getUserId();
}
}
class Address{
String city;
String State;
int zip;
String Country;
public Address(String city, String state, int zip, String country) {
this.city = city;
State = state;
this.zip = zip;
Country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return State;
}
public void setState(String state) {
this.State = state;
}
}
class Book {
int bookId;
String title;
String description;
String author;
int totalQuantity;
int availableQuantity;
double price;
double rentPerDay;
public Book(int bookId, String title, String description, String author, int
totalQuantity, int availableQuantity,
double price, double rentPerDay) {
super();
this.bookId = bookId;
this.title = title;
this.description = description;
this.author = author;
this.totalQuantity = totalQuantity;
this.availableQuantity = availableQuantity;
this.price = price;
this.rentPerDay = rentPerDay;
}
public Book() {}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getTotalQuantity() {
return totalQuantity;
}
}
-----------------------------------------------------------------------------------
-
Customer and Book File-Collection:(L2-2)
import java.util.*;
import java.io.*;
class Source{
public static void main(String args[])
{
}}
class Book implements Serializable{
int bookId;
String title;
String description;
String author;
int totalQuantity;
int availableQuantity;
double price;
double rentPerDay;
public Book(int bookId, String title, String description, String author, int
totalQuantity, int availableQuantity,
double price, double rentPerDay) {
this.bookId = bookId;
this.title = title;
this.description = description;
this.author = author;
this.totalQuantity = totalQuantity;
this.availableQuantity = availableQuantity;
this.price = price;
this.rentPerDay = rentPerDay;
}
public Book() {}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getTotalQuantity() {
return totalQuantity;
}
@Override
public void insertBooks(Book book) {
if(book!=null){
booksList.add(book);}
}
@Override
public void writeBooks() {
if(booksList.isEmpty()==false){
try {
ObjectOutputStream oos1 = new ObjectOutputStream(new
FileOutputStream("books.txt"));
for (Book t : booksList) {
oos1.writeObject(t);
}
oos1.close();
} catch (FileNotFoundException fnfe2) {
System.out.println("FileNotFoundException2");
} catch (IOException ioe2) {
System.out.println("IOException2");
}
catch (Exception e) {
System.out.println("hiii");
}
}
}
@Override
public List<Book> readBooks() {
try {
ObjectInputStream ois1 = new ObjectInputStream(new
FileInputStream("books.txt"));
while (ois1.available() > 0) {
Book t = (Book) ois1.readObject();
booksList.add(t);
ois1.close();
}
} catch (FileNotFoundException fnfe4) {
System.out.println("FileNotFoundException4");
} catch (IOException ioe4) {
System.out.println("IOException4");
} catch (ClassNotFoundException cnfe2) {
System.out.println("ClassNotFoundException2");
}
return booksList;
}
}
class Customer implements Serializable{
int userId;
String emailId;
String password;
String firstName;
String lastName;
String city;
String gender;
long phoneNumber;
Address address;
public Customer(int userId, String emailId, String password, String firstName,
String lastName, String city,
String gender, long phoneNumber, Address address) {
this.userId = userId;
this.emailId = emailId;
this.password = password;
this.firstName = firstName;
this.lastName = lastName;
this.city = city;
this.gender = gender;
this.phoneNumber = phoneNumber;
this.address = address;
}
@Override
public String toString() {
return "Customer [userId=" + userId + ", emailId=" + emailId + ", password=" +
password + ", firstName="
+ firstName + ", lastName=" + lastName + ", city=" + city + ", gender=" +
gender + ", phoneNumber="
+ phoneNumber + ", address=" + address + "]";
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public long getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(long phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
interface CustomerService{
void insertCustomer(Customer customer);
void writeCustomer();
List<Customer> readCustomer();
}
class CustomerServiceImpl implements CustomerService {
public static ArrayList<Customer> customerList=new ArrayList<Customer>();
return customerList;
}
}
class Address implements Serializable{
String city;
String State;
int zip;
String Country;
public Address(String city, String state, int zip, String country) {
this.city = city;
State = state;
this.zip = zip;
Country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return State;
}
public void setState(String state) {
this.State = state;
}
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.naming.InvalidNameException;
class Address {
}
@Override
public String toString() {
return "Customer [userId=" + userId + ", emailId=" + emailId + ",
password=" + password + ", firstName="
+ firstName + ", lastName=" + lastName + ", city=" + city +
", gender=" + gender + ", phoneNumber="
+ phoneNumber + ", address=" + address + "]";
}
}
class Admin
{
private String name;
String email;
String password;
public Admin()
{
}
public Admin(String name, String email, String password) {
super();
this.name = name;
this.email = email;
this.password = password;
}
}
interface AdminService{
public boolean validateAdmin(String email,String password);
}
class AdminServiceImpl implements AdminService
{
public static Admin[] adminArray=new Admin[5];
AdminServiceImpl()
{
adminArray[0]=new Admin("Krithick","krithick@gmail.com","krithi");
adminArray[1]=new Admin("Raja","rajan@gmail.com","rajan#345");
adminArray[2]=new Admin("Chandrav","chand@gmail.com","wel$234");
adminArray[3]=new Admin("Ankit","ankit@gmail.com","kit@56");
adminArray[4]=new Admin("Akilan","akilan@gmail.com","ak*76");
}
@Override
public boolean validateAdmin(String email, String password) {
// TODO Auto-generated method stub
for(int i=0;i<5;i++){
if(adminArray[i].email.equals(email) &&
adminArray[i].password.equals(password)){
return true;
}
}
return true;
}
}
interface CustomerService {
}
@Override
public boolean validateCustomer(String email, String password) {
// TODO Auto-generated method stub
for(int i=0;i<5;i++){
if(customerArray[i].emailId.equals(email) &&
customerArray[i].password.equals(password)){
return true;
}
}
return true;
}
}
class Source{
}
}