Java Questions
Java Questions
DESCRIPTION
1. Create Admin and Toy class as per the given structure with setter and getter
methods and create the object for Admin and Toy object use the setter methods to pass
the value to the attributes and print the information.
2 Create a constructor for Admin and Toy with the attributes as parameter. create the
objects using parameterized constructor in the main method of the Source class.
Sample Input
120
Rubber Ducky
Toy
1
3
200
20
20
200
Sample output
ID: 120
ToyName: Rubber Ducky
ToyType: Toy
Min Age: 1
Max Age: 3
Price: 200.0
Quanitity: 20
RefundableAmount: 20.0
Refundable Deposit: 200.0
Code:
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
class Admin{
Admin(){}
this.email=email;
this.password=password;
this.name=name;
// Getter1
return email;
// Setter1
this.email = email;
// Getter2
// Setter2
this.password = password;
// Getter3
return name;
// Setter3
this.name = name;
class Toy{
public Toy(){}
public Toy(int toyId, String toyName, String toyType, int minAge,
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
return toyId;
// Setter1
this.toyId = toyId;
// Getter2
return toyName;
// Setter2
public void setToyName(String toyName) {
this.toyName = toyName;
// Getter3
return toyType;
// Setter3
this.toyType = toyType;
// Getter4
return minAge;
// Setter4
this.minAge = minAge;
// Getter5
return maxAge;
// Setter5
// Getter6
return price;
// Setter6
this.price = price;
// Getter7
return quantity;
// Setter7
this.quantity=quantity;
// Getter8
return rentalAmount;
// Setter8
this.rentalAmount = rentalAmount;
}
// Getter9
return refundableDeposit;
// Setter9
this.refundableDeposit = refundableDeposit;
int i1=Integer.parseInt(str1);
toy.setToyId(i1);
toy.setToyName(str2);
String str3 = in.nextLine();
toy.setToyType(str3);
int i4=Integer.parseInt(str4);
toy.setMinAge(i4);
int i5=Integer.parseInt(str4);
toy.setMaxAge(i5);
int i6=Integer.parseInt(str6);
toy.setPrice(i6);
int i7=Integer.parseInt(str7);
toy.setQuantity(i7);
int i8=Integer.parseInt(str8);
toy.setRentalAmount(i8);
String str9 = in.nextLine();
int i9=Integer.parseInt(str9);
toy.setRefundableDeposit(i9);
}
Question 7
Inheritance - Sub classes for Toy class- 4.9
bookmark_border
subject Coding
casino 100 points
DESCRIPTION
Sample Input
1
Remote Car
Electronic
4
12
500
20
100
500
5
Remote
Sample output
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
interface AdminService{
class Toy{
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;
}
return toyId;
this.toyId=toyId;
return toyName;
return toyType;
return minAge;
return maxAge;
return price;
return quantity;
return rentalAmount;
return refundableDeposit;
}
public void setToyName(String toyName){
this.toyName=toyName;
this.toyType=toyType;
this.minAge=minAge;
this.maxAge=maxAge;
this.price=price;
this.quantity=quantity;
this.rentalAmount=rentalAmount;
this.refundableDeposit=refundableDeposit;
}
class ElectronicToy extends Toy{
super(toyId,toyName,toyType,minAge,maxAge,price,quantity,rentalAmount,refundableDeposit);
this.numberOfBatteries=numberOfBatteries;
this.operatingMode=operatingMode;
"\nType: "+super.getToyType()+
"\nMode: "+operatingMode+
"\nBatteries: "+numberOfBatteries;
super(toyId,toyName,toyType,minAge,maxAge,price,quantity,rentalAmount,refundableDeposit);
this.noOfSpeakers=noOfSpeakers;
{
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";
}*/
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,
numberOfBatteries,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,no
OfSpeakers);
System.out.println(m.toString());
}
Question 4
Java-Customer and Admin Login 4-11,12
bookmark_border
subject Coding
casino 100 points
DESCRIPTION
1. Provide login facility for admin and customer. After successful login, display
respective console dashboards (menu). Now user can perform his respective actions.
2 get the console input from the user 1 for Customer and 2 for Admin , Name and
password to validate the user based on the role functionalities should be display as
below.
Customers
1.Rent Toys
Admin
1.Insert Toys
2.Update Toys
3.Delete Toys
4,Search Toys
Sample Input
1
Krithick
xxxxxxxx
Sample output
1.Rent Toys
2.Rental Information
Sample Input
2
admin
xxxxxxxxxxxx
Sample output
1.Insert Toys
2.Update Toys
3.Delete Toys
4.Search Toys
Code:
import java.util.Scanner;
interface AdminService{
interface CustomerService{
class Customer
public Customer(int customerId, String customerName, String email, String password, String
address){
this.customerId = customerId;
this.customerName = customerName;
this.password = password;
this.address = address;
this.email = email;
return password;
return email;
class Admin
this.password = password;
this.name = name;
this.email = email;
return password;
return email;
adminArray[0]=new Admin("Krithick","[email protected]","krithi");
adminArray[1]=new Admin("Rajan","[email protected]","rajan#345");
adminArray[2]=new Admin("Chandrav","[email protected]","wel$234");
adminArray[3]=new Admin("Ankit","[email protected]","kit@56");
adminArray[4]=new Admin("Akilan","[email protected]","ak*76");
for(Admin a:adminArray){
return true;
return false;
public CustomerServiceImpl()
for(Customer c:customerArray){
return true;
return false;
int n = sc.nextInt();
if(n==1){
if(flag)
System.out.println("1.Rent Toys");
else if(n==2){
if(flag)
}
Question 2
Java- Customer and Address class - 4.2
bookmark_border
subject Coding
casino 100 points
DESCRIPTION
1. Create Customer and Address class as per the given structure with setter and
getter methods and create the object for Customer and Address object use the setter
methods to pass the value to the attributes and print the information.
Note:Customer and Address should have has a relationship between the classes
2 Create a constructor for Customer and Address with the attributes as parameter.
create the objects using parameterized constructor in the main method of the Source
class.
3.Override toString method and it should return the concatenated string of the class
attributes
Sample Input
100
Chandrav
Jai@123
[email protected]
Chennai
TamilNadu
600045
India
Sample output
DESCRIPTION
This program should display all the toys to the user and user can rent the toy
by entering the toyid from console
The display method display the rented toy by the customer as below
Sample Input
120
Sample output
Toy Name: Rubber Ducky
Toy Type: Toy
Quantity: 200
RentalAmount: 20
Code:
import java.util.Scanner;
interface CustomerService
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;
}
return toyId;
return toyName;
return toyType;
return quantity;
return rentalAmt;
CustomerServiceImpl()
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);
{
for(int i=0;i<4;i++){
if(availableToys[i].getToyId()==toyId){
System.out.println("Quantity: "+availableToys[i].getQuantity());
System.out.print("RentalAmount: "+availableToys[i].getRentalAmount());
break;
int toyId=sc.nextInt();
cs.rent(toyId);
}
Question 3
Java- Admin -Service 4.6 7
bookmark_border
subject Coding
casino 100 points
DESCRIPTION
1 . Add Toys
2. UpdateToys
3 Delete Toys
4 Display Toys
Note:Below is the sample input for adding a toy to a toyArray and the output is
a toy object since only one object is added hence the output is for a single toy
. when multiple toys are added the getToys method should return all the toys
Sample Input
120
Rubber Ducky
Toy
1
3
200
20
20
200
30
Sample output
Toy Name: Rubber Ducky
Toy Type: Toy
Quantity: 200
RentalAmount: 20
Code:
import java.util.*;
interface AdminService{
Toy[] getToys();
@Override
toyArray[count]=toy;
count++;
if(toyArray[i].getToyId()==toy.getToyId()) {
toyArray[i]=toy;
break;
for(int i=0;i<=count;i++) {
if(toyArray[i].getToyId()==toy.getToyId()) {
toyArray[i]=null;
break;
return toyArray;
class Toy{
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;
return toyId;
this.toyId = toyId;
return minAge;
this.minAge = minAge;
return maxAge;
this.maxAge = maxAge;
}
public int getQuantity() {
return quantity;
this.quantity = quantity;
return toyName;
this.toyName = toyName;
return toyType;
this.toyType = toyType;
return price;
this.price = price;
}
public double getRentalAmount() {
return rentalAmount;
this.rentalAmount = rentalAmount;
return refundableDeposit;
this.refundableDeposit = refundableDeposit;
class Source{
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();
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();
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();
adm2.deleteToy(t2);
break;
case 4:
toys=adm3.getToys();
for(int i=0;i<toys.length;i++) {
System.out.println(adm3.toString());
s.close();
}
Question 6
Java- Search Customer and Toy 4.10
bookmark_border
subject Coding
casino 100 points
DESCRIPTION
3 get the console input from the user 1.for search customer 2 for search toys
Sample Input
2
120
Sample output
Id: 120
Toy Name: Rubber Ducky
Sample Input
1
100
Sample Output
Id: 100
Name: Chandrav
Code:
import java.util.Scanner;
interface AdminService {
interface CustomerService {
class Customer {
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;
}
return this.customerId;
return this.customerName;
class Toy {
public Toy() {
}
public Toy(int toyId, String toyName, String toyType, int minAge, int maxAge, double price, 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;
return this.toyId;
return this.toyName;
if (customerArray[i].getCustomerId() == id) {
return customerArray[i];
return null;
AdminServiceImpl() {
availableToys[0] = new Toy(120, "Rubber Ducky", "Toy", 1, 3, 200, 20, 20, 200);
if (availableToys[i].getToyId() == id) {
return availableToys[i];
return null;
int ch=sc.nextInt();
int id=sc.nextInt();
sc.close();
switch(ch) {
Customer customer=customerService.searchCustomer(id);
System.out.println(customerService.toString());
break;
Toy toy=adminService.searchToy(id);
System.out.println(toy.toString());
break;