Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 48

1.

Toy and admin class


import java.util.Arrays;

import java.util.Collections;

import java.util.List;

import java.util.Scanner;

class Admin{

private String email;

private String password;

private String name;

Admin(){}

Admin(String email, String password, String name){

this.email=email;

this.password=password;

this.name=name;

// Getter1

public String getEmail() {

return email;

// Setter1

public void setEmail(String email) {

this.email = email;
}

// Getter2

// Setter2

public void setPassword(String password) {

this.password = password;

// Getter3

public String getName() {

return name;

// Setter3

public void setName(String name) {

this.name = name;

class Toy{

private int toyId;


private String toyName;

private String toyType;

private int minAge;

private int maxAge;

private int price;

private int quantity;

private int rentalAmount;

private int refundableDeposit;

public Toy(){}

public Toy(int toyId, String toyName, String toyType, int minAge,

int maxAge, int price, int quantity, int rentalAmount,

int refundableDeposit){

this.toyId=toyId;

this.toyName=toyName;

this.toyType=toyType;

this.minAge=minAge;

this.maxAge=maxAge;

this.price=price;

this.quantity=quantity;

this.rentalAmount=rentalAmount;

this.refundableDeposit=refundableDeposit;

}
// Getter1

public int getToyId() {

return toyId;

// Setter1

public void setToyId(int toyId) {

this.toyId = toyId;

// Getter2

public String getToyName() {

return toyName;

// Setter2

public void setToyName(String toyName) {

this.toyName = toyName;

// Getter3

public String getToyType() {

return toyType;

}
// Setter3

public void setToyType(String toyType) {

this.toyType = toyType;

// Getter4

public int getMinAge() {

return minAge;

// Setter4

public void setMinAge(int minAge) {

this.minAge = minAge;

// Getter5

public int getMaxAge() {

return maxAge;

// Setter5

public void setMaxAge(int maxAge) {

this.maxAge = maxAge;

}
// Getter6

public int getPrice() {

return price;

// Setter6

public void setPrice(int price) {

this.price = price;

// Getter7

public int getQuantity() {

return quantity;

// Setter7

public void setQuantity(int quantity) {

this.quantity=quantity;

// Getter8

public int getRentalAmount() {

return rentalAmount;

}
// Setter8

public void setRentalAmount(int rentalAmount) {

this.rentalAmount = rentalAmount;

// Getter9

public int getRefundableDeposit() {

return refundableDeposit;

// Setter9

public void setRefundableDeposit(int refundableDeposit) {

this.refundableDeposit = refundableDeposit;

public class Source

public static void main( String[] args )

Toy toy = new Toy();

Admin admin=new Admin();


Scanner in = new Scanner(System.in);

String str1 = in.nextLine();

int i1=Integer.parseInt(str1);

toy.setToyId(i1);

String str2 = in.nextLine();

toy.setToyName(str2);

String str3 = in.nextLine();

toy.setToyType(str3);

String str4 = in.nextLine();

int i4=Integer.parseInt(str4);

toy.setMinAge(i4);

String str5 = in.nextLine();

int i5=Integer.parseInt(str4);

toy.setMaxAge(i5);
String str6 = in.nextLine();

int i6=Integer.parseInt(str6);

toy.setPrice(i6);

String str7 = in.nextLine();

int i7=Integer.parseInt(str7);

toy.setQuantity(i7);

String str8 = in.nextLine();

int i8=Integer.parseInt(str8);

toy.setRentalAmount(i8);

String str9 = in.nextLine();

int i9=Integer.parseInt(str9);

toy.setRefundableDeposit(i9);

System.out.println("ID: "+ toy.getToyId());

System.out.println("ToyName: "+ toy.getToyName());

System.out.println("ToyType: "+ toy.getToyType());

System.out.println("Min Age: "+ toy.getMinAge());

System.out.println("Max Age: "+ toy.getMaxAge());

System.out.println("Price: "+ toy.getPrice());


System.out.println("Quanitity: "+ toy.getQuantity());

System.out.println("RefundableAmount: "+ toy.getRentalAmount());

System.out.println("Refundable Deposit: "+ toy.getRefundableDeposit());

2.Customer and address class


import java.util.*; class Customer { private int customerId; private String customerName; private String
password; private Address address; private String email; public Customer() { } @Override public String
toString() { String result = customerId + " "; result += customerName + " "; result += password + " ";
result += email + "\n"; result += address; return result; } public Customer(int customerId, String
customerName, String password, Address address, String email) { this.customerId = customerId;
this.customerName = customerName; this.password = password; this.address = address; this.email =
email; } public int getCustomerId() { return customerId; } public void setCustomerId(int customerId)
{ this.customerId = customerId; } public String getCustomerName() { return customerName; } public void
setCustomerName(String customerName) { this.customerName = customerName; } public String
getPassword() { return password; } public void setPassword(String password) { this.password =
password; } public String getpassword() { return password; } public void setpassword(String password)
{ this.password = password; } public Address getAddress() { return address; } public void
setAddress(Address address) { this.address = address; } public String getEmail() { return email; } public
void setEmail(String email) { this.email = email; } } class Address { private String city; private String state;
private int zip; private String country; public Address() { } public Address(String city, String state, int zip,
String country) { this.city = city; this.state = state; this.zip = zip; this.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; } public int getZip() { return zip; } public void
setZip(int zip) { this.zip = zip; } public String getCountry() { return country; } public void setCountry(String
country) { this.country = country; } @Override public String toString() { String result = city + " "; result +=
state + " "; result += zip + " "; result += country; return result; } } public class Source { public static void
main(String[] args) { Scanner scanner = new Scanner(System.in); int customerId =
Integer.parseInt(scanner.next()); String customerName = scanner.next(); String password =
scanner.next(); String email = scanner.next(); String city = scanner.next(); String state = scanner.next();
int zip = Integer.parseInt(scanner.next()); String country = scanner.next(); Address address = new
Address(city, state, zip, country); Customer customer = new Customer(customerId, customerName,
password, address, email); System.out.println(customer); }}

3.toy exception
import java.util.*;

class InvalidAgeException extends RuntimeException{

public InvalidAgeException() {
//super(message);
}

class Toy {
private int id;
private String name;
private int minAge;
private int maxAge;

public Toy() {
}

public Toy(int id, String name, int minAge, int maxAge) throws InvalidAgeException {
if (minAge < 0 || minAge>12 || maxAge > 12 || maxAge<0) {
throw new InvalidAgeException();
} else {
this.id = id;
this.name = name;
this.minAge = minAge;
this.maxAge = maxAge;
}
}

public int getId() {


return id;
}

public void setId(int id) {


this.id = id;
}

public int getMinAge() {

return minAge;
}

public void setMinAge(int minAge) throws InvalidAgeException {


if (minAge < 0 || minAge > 12)
throw new InvalidAgeException();
this.minAge = minAge;
}

public int getMaxAge() {


return maxAge;
}

public void setMaxAge(int maxAge) throws InvalidAgeException {


if (maxAge < 0 ||maxAge > 12)
throw new InvalidAgeException();
this.maxAge = maxAge;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getToyName() {


return name;
}

public void setToyName(String name) {


this.name = name;
}

public class Source {


String[][] toys = new String[5][5];

Source() {
toys[0][0] = "1";
toys[0][1] = "Stickle Bricks";

toys[1][0] = "2";
toys[1][1] = "Robot Dog";

toys[2][0] = "3";
toys[2][1] = "Magic 8 Ball";

toys[3][0] = "4";
toys[3][1] = "Juggling Clubs";

toys[4][0] = "5";
toys[4][1] = "Chutes and Ladders";

}
public static void main(String[] args) throws InvalidAgeException {
Scanner scanner = new Scanner(System.in);

int id = scanner.nextInt();scanner.nextLine();

String name = scanner.nextLine();


int minAge = scanner.nextInt();
int maxAge = scanner.nextInt();

try {
Toy toy = new Toy(id, name, minAge, maxAge);
System.out.println(toy.getToyName());
}
catch (InvalidAgeException e) {
System.out.println("InvalidAgeException");
}
}
}

4.customer exception

import java.util.*;

class InvalidAgeException extends RuntimeException {

/**

*/

private static final long serialVersionUID = -1510453123644668900L;

public InvalidAgeException(String message) {

super(message);

}
}

class Toy {

private int id;

private String name;

private int minAge;

private int maxAge;

public Toy() {

public Toy(int id, String name, int minAge, int maxAge) throws InvalidAgeException {

if (minAge < 0 || maxAge > 12) {

throw new InvalidAgeException("InvalidAgeException");

} else {

this.id = id;

this.name = name;

this.minAge = minAge;

this.maxAge = maxAge;

public int getId() {

return id;
}

public void setId(int id) {

this.id = id;

public int getMinAge() {

return minAge;

public void setMinAge(int minAge) throws InvalidAgeException {

if (minAge < 0)

throw new InvalidAgeException("InvalidAgeException");

this.minAge = minAge;

public int getMaxAge() {

return maxAge;

public void setMaxAge(int maxAge) throws InvalidAgeException {

if (maxAge > 12)

throw new InvalidAgeException("InvalidAgeException");

this.maxAge = maxAge;
}

public String getName() {

return name;

public void setName(String name) {

this.name = name;

public String getToyName() {

return name;

public void setToyName(String name) {

this.name = name;

public class Source {

String[][] toys = new String[5][5];

Source() {

toys[0][0] = "1";
toys[0][1] = "Stickle Bricks";

toys[1][0] = "2";

toys[1][1] = "Robot Dog";

toys[2][0] = "3";

toys[2][1] = "Magic 8 Ball";

toys[3][0] = "4";

toys[3][1] = "Juggling Clubs";

toys[4][0] = "5";

toys[4][1] = "Chutes and Ladders";

public static void main(String[] args) throws Exception {

Scanner scanner = new Scanner(System.in);

int id = Integer.parseInt(scanner.nextLine());

String name = scanner.nextLine();

int minAge = Integer.parseInt(scanner.nextLine());

int maxAge = Integer.parseInt(scanner.nextLine());

try {

Toy toy = new Toy(id, name, minAge, maxAge);

System.out.println(toy.getToyName());
} catch (InvalidAgeException e) {

System.out.println(e.getMessage());

5.admin service
import java.util.*;

interface AdminService {

void addToy(Toy toy);

void updateToy(Toy toy);

void deleteToy(Toy toy);

Toy[] getToys();

class AdminServiceImpl implements AdminService {

public static Toy[] toyArray = new Toy[5];

public static int count = 0;

@Override

public void addToy(Toy toy) {

toyArray[count] = toy;
count++;

public void updateToy(Toy toy) {

for (int i = 0; i <= count; i++) {

if (toyArray[i].getToyId() == toy.getToyId()) {

toyArray[i] = toy;

break;

public void deleteToy(Toy toy) {

for (int i = 0; i <= count; i++) {

if (toyArray[i].getToyId() == toy.getToyId()) {

toyArray[i] = null;

break;

public Toy[] getToys() {

return toyArray;

}
}

class Toy {

private int toyId, minAge, maxAge, quantity;

private String toyName, toyType;

private double price, rentalAmount, refundableDeposit;

Toy(int id, String name, String type, int min, int max, double price, int quant, double rent, double
refund) {

this.toyId = id;

this.toyName = name;

this.toyType = type;

this.minAge = min;

this.maxAge = max;

this.price = price;

this.quantity = quant;

this.rentalAmount = rent;

this.refundableDeposit = refund;

public int getToyId() {

return toyId;

public void setToyId(int toyId) {

this.toyId = toyId;
}

public int getMinAge() {

return minAge;

public void setMinAge(int minAge) {

this.minAge = minAge;

public int getMaxAge() {

return maxAge;

public void setMaxAge(int maxAge) {

this.maxAge = maxAge;

public int getQuantity() {

return quantity;

public void setQuantity(int quantity) {

this.quantity = quantity;

}
public String getToyName() {

return toyName;

public void setToyName(String toyName) {

this.toyName = toyName;

public String getToyType() {

return toyType;

public void setToyType(String toyType) {

this.toyType = toyType;

public double getPrice() {

return price;

public void setPrice(double price) {

this.price = price;

}
public double getRentalAmount() {

return rentalAmount;

public void setRentalAmount(double rentalAmount) {

this.rentalAmount = rentalAmount;

public double getRefundableDeposit() {

return refundableDeposit;

public void setRefundableDeposit(double refundableDeposit) {

this.refundableDeposit = refundableDeposit;

public String toString() {

return ("Toy Name: " + this.toyName + "\nToy Type: " + this.toyType + "\nQuantity: " + this.quantity

+ "\nRentalAmount: " + this.rentalAmount);

class Source {

public static void main(String args[]) {

Scanner s = new Scanner(System.in);


int choice = s.nextInt();

int id, min, max, quantity;

String name, type;

double price, rent, refund;

Toy[] toys;

switch (choice) {

case 1:

if (s.hasNext()) {

id = s.nextInt();

name = s.next();

type = s.next();

min = s.nextInt();

max = s.nextInt();

price = s.nextDouble();

quantity = s.nextInt();

rent = s.nextDouble();

refund = s.nextDouble();

Toy t = new Toy(id, name, type, min, max, price, quantity, rent, refund);

AdminService adm = new AdminServiceImpl();

adm.addToy(t);

toys = adm.getToys();

for (int i = 0; i < toys.length; i++) {

System.out.println(adm.toString());

}
break;

case 2:

id = s.nextInt();

name = s.next();

type = s.next();

min = s.nextInt();

max = s.nextInt();

price = s.nextDouble();

quantity = s.nextInt();

rent = s.nextDouble();

refund = s.nextDouble();

Toy t1 = new Toy(id, name, type, min, max, price, quantity, rent, refund);

AdminService adm1 = new AdminServiceImpl();

adm1.updateToy(t1);

System.out.println(adm1.toString());

break;

case 3:

id = s.nextInt();

name = s.next();

type = s.next();

min = s.nextInt();

max = s.nextInt();

price = s.nextDouble();

quantity = s.nextInt();

rent = s.nextDouble();
refund = s.nextDouble();

Toy t2 = new Toy(id, name, type, min, max, price, quantity, rent, refund);

AdminService adm2 = new AdminServiceImpl();

adm2.deleteToy(t2);

break;

case 4:

AdminService adm3 = new AdminServiceImpl();

toys = adm3.getToys();

for (int i = 0; i < toys.length; i++) {

System.out.println(adm3.toString());

s.close();

6.customer and admin login

import java.util.Scanner;

interface AdminService{

boolean validateAdmin(String email, String password);

interface CustomerService{
boolean validateCustomer(String email, String password);

class Customer

private int customerId;

private String customerName;

private String email;

private String password;

private String address;

// public Customer(){

// }

public Customer(int customerId, String customerName, String email, String password, String address) {

// super();

this.customerId = customerId;

this.customerName = customerName;

this.password = password;

this.address = address;

this.email = email;

public String getPassword(){

return password;

public String getEmail(){

return email;
}

class Admin

private String name;

private String email;

private String password;

// public static Admin adminArray[]=new Admin[];

// public Admin()

// {

// }

public Admin(String name,String email, String password) {

// super();

this.password = password;

this.name = name;

this.email = email;

public String getPassword(){

return password;

public String getEmail(){


return email;

class AdminServiceImpl extends CustomerServiceImpl implements AdminService

public static Admin[] adminArray=new Admin[5];

AdminServiceImpl()

adminArray[0]=new Admin("Krithick","krithick@gmail.com","krithi");

adminArray[1]=new Admin("Rajan","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");

public boolean validateAdmin(String email,String password)

for(Admin a:adminArray){

if(a.getEmail().equals(email) && a.getPassword().equals(password))

return true;

return false;
}

class CustomerServiceImpl implements CustomerService

public static Customer[] customerArray=new Customer[5];

public CustomerServiceImpl()

customerArray[0]=new Customer(100, "Karthi","kar@gmail.com","kar#2","Bangalore");

customerArray[1]=new Customer(101, "Kumar","km@mail.com","km#2","Bangalore");

customerArray[2]= new Customer(102, "Rakesh","rak@mail.com","rak#45","Chennai");

customerArray[3]=new Customer(103, "Rakshan","shan@mail.com","an#2","Mumbai");

customerArray[4]=new Customer(104, "Virat","rat@mail.com","at#45","Pune");

public boolean validateCustomer(String email,String password)

for(Customer c:customerArray){

if(c.getEmail().equals(email) && c.getPassword().equals(password))

return true;

return false;
}

public class Source {

public static void main(String args[])

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

if(n==1){

String email = sc.next();

String password = sc.next();

CustomerServiceImpl cs = new CustomerServiceImpl();

// CustomerServiceImpl csi = new AdminServiceImpl();

boolean flag = cs.validateCustomer(email, password);

if(flag)

System.out.println("1.Rent Toys");

System.out.println("2.Rental Information for the logged in Customer.");

else if(n==2){

String email = sc.next();

String password = sc.next();

AdminService as = new AdminServiceImpl();

boolean flag = as.validateAdmin(email, password);

if(flag)
{

System.out.println("1.Insert Toys"+"\n2.Update Toys"+"\n3.Delete Toys"+"\n4.Search Toys");

7.customer service

import java.util.Scanner;

interface CustomerService

void rent(int toyId);

void display();

class Toy{

int toyId;

String toyName;

String toyType;

int minAge;

int maxAge;

double price;
int rentalAmt;

int refundableDeposit;

int quantity;

public Toy(int toyId, String toyName, String toyType, int minAge, int maxAge, double price, int
refundableDeposit,int quantity, int rentalAmt){

this.toyId=toyId;

this.toyName=toyName;

this.toyType=toyType;

this.minAge=minAge;

this.maxAge=maxAge;

this.price=price;

this.rentalAmt=rentalAmt;

this.refundableDeposit=refundableDeposit;

this.quantity=quantity;

public int getToyId(){

return toyId;

public String getToyName(){

return toyName;

public String getToyType(){

return toyType;

public int getQuantity(){

return quantity;

public int getRentalAmount(){

return rentalAmt;
}

class CustomerServiceImpl implements CustomerService

public static Toy availableToys[]=new Toy[4];

public Toy customerToysRentalInfo[]=new Toy[2];

CustomerServiceImpl()

availableToys[0]=new Toy(120,"Rubber Ducky","Toy",1,3,200,20,200,20);

availableToys[1]=new Toy(130,"Car","Toy",1,5,100,30,20,100);

availableToys[2]=new Toy(150,"Kite","Toy",3,8,100,50,20,100);

availableToys[3]=new Toy(180,"Airplane","Toy",4,7,500,30,50,20);

public void rent(int toyId)

for(int i=0;i<4;i++){

if(availableToys[i].getToyId()==toyId){

System.out.println("Toy Name: "+availableToys[i].getToyName());

System.out.println("Toy Type: "+availableToys[i].getToyType());

System.out.println("Quantity: "+availableToys[i].getQuantity());

System.out.print("RentalAmount: "+availableToys[i].getRentalAmount());

break;

public void display()

{
}

public class Source {

public static void main( String[] args )

Scanner sc=new Scanner(System.in);

int toyId=sc.nextInt();

CustomerService cs=new CustomerServiceImpl();

cs.rent(toyId);

8.customer and toy search operation

import java.util.Scanner;

interface AdminService {

public Toy searchToy(int id);

interface CustomerService {

public Customer searchCustomer(int id);

}
class Customer {

private int customerId;

private String customerName;

private String email;

private String password;

private String address;

public Customer() {

public Customer(int customerId, String customerName, String email, String password, String address) {

super();

this.customerId = customerId;

this.customerName = customerName;

this.email = email;

this.password = password;

this.address = address;

public int getCustomerId() {

return this.customerId;

public String getCustomerName() {


return this.customerName;

public String toString() {

return "Id: " + this.customerId + "\nName: " + this.customerName;

class Toy {

private int toyId;

private String toyName;

private String toyType;

private int minAge;

private int maxAge;

private double price;

private int quantity;

private int rentalAmt;

private int refundableDeposit;

public String toString;

public Toy() {

public Toy(int toyId, String toyName, String toyType, int minAge, int maxAge, double price, int
rentalAmt,
int refundableDeposit, int quantity) {

this.toyId = toyId;

this.toyName = toyName;

this.toyType = toyType;

this.minAge = minAge;

this.maxAge = maxAge;

this.price = price;

this.rentalAmt = rentalAmt;

this.refundableDeposit = refundableDeposit;

this.quantity = quantity;

this.toString = "Id: " + this.toyId + "\nToyName: " + this.toyName;

public int getToyId() {

return this.toyId;

public String getToyName() {

return this.toyName;

public String toString() {

return "Id: " + this.toyId + "\nToyName: " + this.toyName;

}
class CustomerServiceImpl extends Customer implements CustomerService {

public static Customer[] customerArray = new Customer[5];

public CustomerServiceImpl() {

customerArray[0] = new Customer(100, "Karthi", "kar@gmail.com", "kar#2", "Bangalore");

customerArray[1] = new Customer(101, "Kumar", "km@mail.com", "km#2", "Bangalore");

customerArray[2] = new Customer(102, "Rakesh", "rak@mail.com", "rak#45", "Chennai");

customerArray[3] = new Customer(103, "Rakshan", "shan@mail.com", "an#2", "Mumbai");

customerArray[4] = new Customer(104, "Virat", "rat@mail.com", "at#45", "Pune");

public Customer searchCustomer(int id) {

for (int i = 0; i < 5; i++) {

if (customerArray[i].getCustomerId() == id) {

return customerArray[i];

return null;

class AdminServiceImpl implements AdminService {

static Toy availableToys[] = new Toy[5];


Toy toy = new Toy();

AdminServiceImpl() {

availableToys[0] = new Toy(120, "Rubber Ducky", "Toy", 1, 3, 200, 20, 20, 200);

availableToys[1] = new Toy(130, "Car", "Toy", 1, 5, 100, 30, 20, 100);

availableToys[2] = new Toy(150, "Kite", "Toy", 3, 8, 100, 50, 20, 50);

availableToys[3] = new Toy(180, "Airplane", "Toy", 4, 7, 500, 30, 50, 20);

public Toy searchToy(int id) {

for (int i = 0; i < 4; i++) {

if (availableToys[i].getToyId() == id) {

return availableToys[i];

return null;

public class Source {

public static void main(String[] args) {

//Scanner sc=new Scanner(System.in);

//int ch=sc.nextInt();

//int id=sc.nextInt();

//sc.close();
//switch(ch) {

//case 1: CustomerService customerService=new CustomerServiceImpl();

// Customer customer=customerService.searchCustomer(id);

// System.out.println(customerService.toString());

// break;

//case 2: AdminService adminService=new AdminServiceImpl();

// Toy toy=adminService.searchToy(id);

// System.out.println(toy.toString());

// break;

//default

: System.out.println("Invalid Choice");

//}

9.inheritance toy class

import java.util.Arrays;

import java.util.Collections;

import java.util.List;

import java.util.Scanner;
interface AdminService{

class AdminServiceImpl implements AdminService{

class Toy{

private int toyId;

private String toyName;

private String toyType;

private int minAge;

private int maxAge;

private double price;

private int quantity;

private double rentalAmount;

private double refundableDeposit;

Toy(int toyId,String toyName,String toyType,int minAge,int maxAge,double price,int quantity,double


rentalAmount,double refundableDeposit){

this.toyId=toyId;

this.toyName=toyName;

this.toyType=toyType;

this.minAge=minAge;

this.maxAge=maxAge;

this.price=price;

this.quantity=quantity;

this.rentalAmount=rentalAmount;

this.refundableDeposit=refundableDeposit;

public int getToyId(){

return toyId;

}
public void setToyId(int toyId){

this.toyId=toyId;

public String getToyName(){

return toyName;

public String getToyType(){

return toyType;

public int getMinAge(){

return minAge;

public int getMaxAge(){

return maxAge;

public double getPrice(){

return price;

public int getQuantity(){

return quantity;

public double getRentalAmount(){

return rentalAmount;

public double getRefundableDeposit(){

return refundableDeposit;

public void setToyName(String toyName){

this.toyName=toyName;
}

public void setToyType(String toyType){

this.toyType=toyType;

public void setMinAge(int minAge){

this.minAge=minAge;

public void setMaxAge(int maxAge){

this.maxAge=maxAge;

public void setPrice(double price){

this.price=price;

public void setQuantity(int quantity){

this.quantity=quantity;

public void setRentalAmount(double rentalAmount){

this.rentalAmount=rentalAmount;

public void setRefundableDeposit(double refundableDeposit){

this.refundableDeposit=refundableDeposit;

}
class ElectronicToy extends Toy{

public int numberOfBatteries;

public String operatingMode;

ElectronicToy(int toyId,String toyName,String toyType,int minAge,int maxAge,double price,int


quantity,double rentalAmount,double refundableDeposit,int numberOfBatteries,String operatingMode){

super(toyId,toyName,toyType,minAge,maxAge,price,quantity,rentalAmount,refundableDeposit);

this.numberOfBatteries=numberOfBatteries;

this.operatingMode=operatingMode;

public String toString(){

return "ToyName: "+super.getToyName()+

"\nType: "+super.getToyType()+

"\nMode: "+operatingMode+

"\nBatteries: "+numberOfBatteries;

class MusicalToy extends Toy{

public int noOfSpeakers;

MusicalToy(int toyId,String toyName,String toyType,int minAge,int maxAge,double price,int


quantity,double rentalAmount,double refundableDeposit,int noOfSpeakers){

super(toyId,toyName,toyType,minAge,maxAge,price,quantity,rentalAmount,refundableDeposit);

this.noOfSpeakers=noOfSpeakers;

public String toString(){

return "ToyName: "+super.getToyName()+

"\nType: Musical "+super.getToyType()+"\nSpeaker: "+noOfSpeakers;

public class Source


{

String[][] toys=new String[5][5];

Source()

toys[0][0]="1";

toys[0][1]="Stickle Bricks";

toys[1][0]="2";

toys[1][1]="Robot Dog";

toys[2][0]="3";

toys[2][1]="Magic 8 Ball";

toys[3][0]="4";

toys[3][1]="Juggling Clubs";

toys[4][0]="5";

toys[4][1]="Chutes and Ladders";

/*public String getToy(int age)

}*/

public static void main( String[] args )

AdminService adminService=new AdminServiceImpl();

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();
if(n==1){

String toyName=sc.nextLine();

String toyType=sc.nextLine();

sc.next();

int minAge=sc.nextInt();

int maxAge=sc.nextInt();

double price=sc.nextDouble();

int quantity=sc.nextInt();

double rentalAmount=sc.nextDouble();

double refundableDeposit=sc.nextDouble();

int numberOfBatteries=sc.nextInt();

String operatingMode=sc.next();

ElectronicToy e=new
ElectronicToy(1,toyName,toyType,minAge,maxAge,price,quantity,rentalAmount,refundableDeposit,num
berOfBatteries,operatingMode);

System.out.println(e.toString());

}else if(n==2){

String toyName=sc.next();

String toyType=sc.nextLine();

int minAge=sc.nextInt();

int maxAge=sc.nextInt();

double price=sc.nextDouble();

int quantity=sc.nextInt();

double rentalAmount=sc.nextDouble();

double refundableDeposit=sc.nextDouble();

int noOfSpeakers=sc.nextInt();

MusicalToy m=new
MusicalToy(1,toyName,toyType,minAge,maxAge,price,quantity,rentalAmount,refundableDeposit,noOfS
peakers);

System.out.println(m.toString());
}

You might also like