Professional Documents
Culture Documents
Q1
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
Player p = new Player();
System.out.println("Enter Name:");
String n = sc.nextLine();
System.out.println("Enter Age:");
int a = sc.nextInt();
sc.nextLine();
System.out.println("Enter Country:");
String s = sc.nextLine();
p.setName(n);
p.setAge(a);
p.setCountry(s);
System.out.println("Player Details:");
System.out.println("Name:"+p.getName());
System.out.println("Age:"+p.getAge());
System.out.println("Country:"+p.getCountry());
}
}
public class Player{
private String name;
private int age;
private String country;
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return age;
}
public void setCountry(String country)
{
this.country = country;
}
public String getCountry()
{
return country;
}
}
Q2
import java.io.*;
import java.util.*;
class Main{
public static void main(String[] args) throws Exception{
Scanner sc =new Scanner(System.in);
ItemType p = new ItemType();
System.out.println("Enter the item type name");
String n = sc.nextLine();
System.out.println("Enter the cost per day");
double a = sc.nextDouble();
System.out.println("Enter the deposit");
double b = sc.nextDouble();
p.setName(n);
p.setCostPerDay(a);
p.setDeposit(b);
p.display();
}
}
import java.text.DecimalFormat;
public class ItemType {
DecimalFormat df = new DecimalFormat("0.00");
private String name;
private double costPerDay;
private double deposit;
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setCostPerDay(double costPerDay )
{
this.costPerDay = costPerDay;
}
public double getCostPerDay()
{
return costPerDay;
}
public void setDeposit(double deposit)
{
this.deposit = deposit;
}
public double getDeposit()
{
return deposit;
}
public void display(){
System.out.println("Item type details");
System.out.println("Name : "+getName());
double x = getCostPerDay();
System.out.println("CostPerDay : "+df.format(x));
double y = getDeposit();
System.out.print("Deposit : "+df.format(y));
}
Q3
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
public static void main(String[]args) throws Exception
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter Object 1 details");
System.out.println("Enter i1");
int a = sc.nextInt();
System.out.println("Enter i2");
int b = sc.nextInt();
StaticIllustration p = new StaticIllustration();
p.seti1(a);
p.seti2(b);
p.displayDetails(1);
System.out.println("Enter Object 2 details");
System.out.println("Enter i1");
a = sc.nextInt();
System.out.println("Enter i2");
b = sc.nextInt();
StaticIllustration p1 = new StaticIllustration();
p1.seti1(a);
p1.seti2(b);
p1.displayDetails(2);
p.displayDetails(1);
}
public class StaticIllustration {
private int i1;
private static int i2;
public void seti1(int i1)
{
this.i1 = i1;
}
public int geti1()
{
return i1;
}
public static void seti2(int a)
{
i2 = a;
}
public static int geti2()
{
return i2;
}
public void displayDetails(int i)
{
System.out.println("Object "+i+" Details : i1 = "+geti1()+",i2 = "+geti2());
}
}
Q4 -> not loading
Q5
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
public static void main(String[]args) throws Exception
{
Scanner sc =new Scanner(System.in);
Ticket t = new Ticket();
System.out.println("Enter no of objects:");
int n = sc.nextInt();
System.out.println("Enter the Total no of tickets:");
int a = sc.nextInt();
while(n>0)
{
System.out.println("Enter the ticketid:");
int b = sc.nextInt();
System.out.println("Enter the price:");
int c = sc.nextInt();
System.out.println("Enter the no of tickets:");
int d = sc.nextInt();
if(t.getTotalnooftickets()>0)
{
a =t.getTotalnooftickets();
}
t.setTicketid(b);
t.setPrice(c);
t.setTotalnooftickets(a);
System.out.println("Total no of tickets: "+t.getTotalnooftickets());
int e = t.Calculatetotalamount(d);
if(e<0)
{
System.out.println("Sorry tickets not available.");
}
else
{
System.out.println("Total amount:"+e);
System.out.println("Total no of ticket after booking:"+t.getTotalnooftickets());
}
n--;
}
}
public class Ticket {
private int ticketid;
private int price;
private static int totalnooftickets;
public void setTicketid(int ticketid)
{
this.ticketid = ticketid;
}
public int getTicketid()
{
return ticketid;
}
public void setPrice(int price)
{
this.price = price;
}
public int getPrice()
{
return price;
}
public static void setTotalnooftickets(int a)
{
totalnooftickets = a;
}
public int getTotalnooftickets()
{
return totalnooftickets;
}
public int Calculatetotalamount(int nooftickets)
{
if(nooftickets<= totalnooftickets)
{
totalnooftickets = totalnooftickets-nooftickets;
return (price*nooftickets);
}
else{
return -1;
}
}
Q6
import java.util.Scanner;
public class Main {
public static void displayDetails(Event e) {
System.out.println("Inside Static Method");
e.display();
}
public void displayDetailsNonStatic(Event e) {
System.out.println("Inside Non-Static Method");
e.display();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Event e = new Event();
System.out.println("Enter the event name");
e.setEventName(sc.nextLine());
System.out.println("Enter the hall name");
e.setHallName(sc.nextLine());
System.out.println("Enter the start date(dd/MM/yyyy)");
e.setStartDate(sc.nextLine());
System.out.println("Enter the end date(dd/MM/yyyy)");
e.setEndDate(sc.nextLine());
System.out.println("Enter the no of people");
e.setNoOfPeople(sc.nextInt());
displayDetails(e);
Main m = new Main();
m.displayDetailsNonStatic(e);
}
public class Event {
private String eventName;
private String hallName;
private String startDate;
private String endDate;
private int noOfPeople;
public String getEventName() {
return eventName;
}
public String getHallName() {
return hallName;
}
public String getStartDate() {
return startDate;
}
public String getEndDate() {
return endDate;
}
public int getNoOfPeople() {
return noOfPeople;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public void setHallName(String hallName) {
this.hallName = hallName;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public void setNoOfPeople(int noOfPeople) {
this.noOfPeople = noOfPeople;
}
public void display() {
System.out.println("Event Name: " + eventName);
System.out.println("Hall Name: " + hallName);
System.out.println("Start Date: " + startDate);
System.out.println("End Date: " + endDate);
System.out.println("No of People: " + noOfPeople);
}