SlideShare a Scribd company logo
1 of 17
Programming
Sample Input: Sample Output:
Name : RamKumar
Address : Kollam
Passport Number : J7546891
Question 1
Write a java program which contains class Passport and class Person.
Compose the class Passport in the class Person. Class Passport contains
default constructor which sets the name, address and passport no. Display
the name of the person, Address and passport number in class Person.
RamKumar
Kollam
J7546891
import java.util.Scanner;
class Passport
{
String Name;
String Address;
String Number;
public Passport(String Name,String Address,String Number)
{
this.Name = Name;
this.Address = Address;
this.Number = Number;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Person
{
Passport passport;
Person(Passport passport){
this .passport = passport;
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
String Address = sc.nextLine();
String Number = sc.next();
Passport p = new Passport(name,Address,Number);
Person person = new Person(p);
System.out.println("Name : " + person.passport.Name);
System.out.println("Address : " + person.passport.Address);
System.out.println("Passport Number : " + person.passport.Number);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Question 2
Write a java program which contains class Heart and class Person.
Compose the class Heart in the class Person. Class Heart contains default
constructor which sets the status of the heart is “Beating” or “Stopped” and
print the status of the heart. In class Person check whether the heart is
beating or stopped.
If it is beating print “Heart is Beating”.
else
Print “Heart beat is Stopped” and make the heart object null.
print the status of the class heart .
Sample Input: Sample Output:
Heart is Beating
Beating
Question 2
Beating
Sample Input: Sample Output:
Heart beat is Stopped
Human is Dead
Stopped
import java.util.*;
class Heart
{
String Status;
Heart(String Status)
{
this.Status = Status;
}
}
public class Human
{
Heart beat;
Human(Heart beat)
{
this.beat = beat;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String Status = sc.nextLine();
Heart beat = new Heart(Status);
Human H = new Human(beat);
if(H.beat.Status.equals("Beating"))
{
System.out.println("Heart is Beating");
}
else {
H = null;
System.out.println("Heart beat is Stopped");
}
try{
System.out.println(H.beat.Status);
}
catch(NullPointerException x){
System.out.println("Human is Dead");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sample Input: Sample Output:
Laptop Name: DELL
Operating System : Windows 10
Question 3
Write a java program which contains class Operating_System, Laptop and
Main. Compose the class Operating_System in class Laptop. Class
Operating_System gets the name of the Operating System. Class Laptop
gets the name of the laptop. In class Main, object for class Laptop is created
and print’s the name of the laptop and name of Operating System.
DELL
Windows 10
import java.util.*;
class Operating_System
{
private String os_name;
public String getOs(){
return os_name;
}
public void setOs(String os_name){
this.os_name = os_name;
}
public String toString(){
return os_name;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Laptop
{
private String Name;
private Operating_System Os;
public Laptop()
{
Os = new Operating_System();
}
public void setName(String Name)
{
this.Name = Name;
}
public Operating_System getOperating_System()
{
return Os;
}
public String toString()
{
return "Laptop Name: " + Name + "nOperating System : " + Os ;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Main {
public static void main(String args[]) {
Laptop laptop = new Laptop();
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
String os = sc.nextLine();
laptop.setName(name);
laptop.getOperating_System().setOs(os);
System.out.println(laptop);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Question 4
Write a java program which contains the class Battery and class Mobile.
Compose the class Battery in class Mobile. In the Class Battery, get
percentage of the charge in the battery. In class Mobile, check the battery
percentage and display the following message.
If battery percentage == 0
Print “Phone is switched Off”
Else if battery percentage lies between 5 to 20.
Print “Please charge your phone”
Else
Print “No need of charging”
import java.util.Scanner;
class Battery
{
int percentage;
public Battery(int percentage)
{
this.percentage=percentage;
}
}
public class Mobile
{
Battery bt;
Mobile(Battery bt)
{
this .bt = bt;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int percentage = sc.nextInt();
Battery bt = new Battery(percentage);
Mobile lenova = new Mobile(bt);
if(lenova.bt.percentage == 0)
{
System.out.print("Phone is switched Off");
}
else if((5 <= lenova.bt.percentage)&& (lenova.bt.percentage<=20) )
{
System.out.print("Please charge your phone");
}
else
{
System.out.print("No need of charging");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
THANK YOU

More Related Content

Similar to java

CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
Codecamp Romania
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
ssuser656672
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4
sotlsoc
 

Similar to java (20)

Dev Day Andreas Roth.pdf
Dev Day Andreas Roth.pdfDev Day Andreas Roth.pdf
Dev Day Andreas Roth.pdf
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab File
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Core Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th MayCore Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th May
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Examples from Pune meetup
Examples from Pune meetupExamples from Pune meetup
Examples from Pune meetup
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Initial Java Core Concept
Initial Java Core ConceptInitial Java Core Concept
Initial Java Core Concept
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docx
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
 
C# Is The Future
C# Is The FutureC# Is The Future
C# Is The Future
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
OOP with Java - continued
OOP with Java - continuedOOP with Java - continued
OOP with Java - continued
 

More from YoshitaSingh5 (9)

WINSEM2022-23_BIT2018_TH_VL2022230501775_ReferenceMaterialI_WedMar0100_00_00I...
WINSEM2022-23_BIT2018_TH_VL2022230501775_ReferenceMaterialI_WedMar0100_00_00I...WINSEM2022-23_BIT2018_TH_VL2022230501775_ReferenceMaterialI_WedMar0100_00_00I...
WINSEM2022-23_BIT2018_TH_VL2022230501775_ReferenceMaterialI_WedMar0100_00_00I...
 
WINSEM2022-23_BIT2018_TH_VL2022230501775_Reference_Material_I_20-01-2023_revi...
WINSEM2022-23_BIT2018_TH_VL2022230501775_Reference_Material_I_20-01-2023_revi...WINSEM2022-23_BIT2018_TH_VL2022230501775_Reference_Material_I_20-01-2023_revi...
WINSEM2022-23_BIT2018_TH_VL2022230501775_Reference_Material_I_20-01-2023_revi...
 
Reflexiveverb.pptx
Reflexiveverb.pptxReflexiveverb.pptx
Reflexiveverb.pptx
 
Definite_and_indefinite_articles.ppt
Definite_and_indefinite_articles.pptDefinite_and_indefinite_articles.ppt
Definite_and_indefinite_articles.ppt
 
Tener___venir.ppt
Tener___venir.pptTener___venir.ppt
Tener___venir.ppt
 
Tener___venir.ppt
Tener___venir.pptTener___venir.ppt
Tener___venir.ppt
 
13-12-2022_Descriptive_methods_1_2.pdf
13-12-2022_Descriptive_methods_1_2.pdf13-12-2022_Descriptive_methods_1_2.pdf
13-12-2022_Descriptive_methods_1_2.pdf
 
Launch Product Crowdfunding Pitch Deck by Slidesgo.pptx
Launch Product Crowdfunding Pitch Deck by Slidesgo.pptxLaunch Product Crowdfunding Pitch Deck by Slidesgo.pptx
Launch Product Crowdfunding Pitch Deck by Slidesgo.pptx
 
design thinking and mvp template
design thinking and mvp templatedesign thinking and mvp template
design thinking and mvp template
 

Recently uploaded

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

java

  • 1.
  • 3. Sample Input: Sample Output: Name : RamKumar Address : Kollam Passport Number : J7546891 Question 1 Write a java program which contains class Passport and class Person. Compose the class Passport in the class Person. Class Passport contains default constructor which sets the name, address and passport no. Display the name of the person, Address and passport number in class Person. RamKumar Kollam J7546891
  • 4. import java.util.Scanner; class Passport { String Name; String Address; String Number; public Passport(String Name,String Address,String Number) { this.Name = Name; this.Address = Address; this.Number = Number; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 5. public class Person { Passport passport; Person(Passport passport){ this .passport = passport; } public static void main(String args[]) { Scanner sc = new Scanner(System.in); String name = sc.nextLine(); String Address = sc.nextLine(); String Number = sc.next(); Passport p = new Passport(name,Address,Number); Person person = new Person(p); System.out.println("Name : " + person.passport.Name); System.out.println("Address : " + person.passport.Address); System.out.println("Passport Number : " + person.passport.Number); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 6. Question 2 Write a java program which contains class Heart and class Person. Compose the class Heart in the class Person. Class Heart contains default constructor which sets the status of the heart is “Beating” or “Stopped” and print the status of the heart. In class Person check whether the heart is beating or stopped. If it is beating print “Heart is Beating”. else Print “Heart beat is Stopped” and make the heart object null. print the status of the class heart .
  • 7. Sample Input: Sample Output: Heart is Beating Beating Question 2 Beating Sample Input: Sample Output: Heart beat is Stopped Human is Dead Stopped
  • 8. import java.util.*; class Heart { String Status; Heart(String Status) { this.Status = Status; } } public class Human { Heart beat; Human(Heart beat) { this.beat = beat; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 9. public static void main(String args[]) { Scanner sc = new Scanner(System.in); String Status = sc.nextLine(); Heart beat = new Heart(Status); Human H = new Human(beat); if(H.beat.Status.equals("Beating")) { System.out.println("Heart is Beating"); } else { H = null; System.out.println("Heart beat is Stopped"); } try{ System.out.println(H.beat.Status); } catch(NullPointerException x){ System.out.println("Human is Dead"); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 10. Sample Input: Sample Output: Laptop Name: DELL Operating System : Windows 10 Question 3 Write a java program which contains class Operating_System, Laptop and Main. Compose the class Operating_System in class Laptop. Class Operating_System gets the name of the Operating System. Class Laptop gets the name of the laptop. In class Main, object for class Laptop is created and print’s the name of the laptop and name of Operating System. DELL Windows 10
  • 11. import java.util.*; class Operating_System { private String os_name; public String getOs(){ return os_name; } public void setOs(String os_name){ this.os_name = os_name; } public String toString(){ return os_name; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 12. class Laptop { private String Name; private Operating_System Os; public Laptop() { Os = new Operating_System(); } public void setName(String Name) { this.Name = Name; } public Operating_System getOperating_System() { return Os; } public String toString() { return "Laptop Name: " + Name + "nOperating System : " + Os ; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 13. public class Main { public static void main(String args[]) { Laptop laptop = new Laptop(); Scanner sc = new Scanner(System.in); String name = sc.nextLine(); String os = sc.nextLine(); laptop.setName(name); laptop.getOperating_System().setOs(os); System.out.println(laptop); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 14. Question 4 Write a java program which contains the class Battery and class Mobile. Compose the class Battery in class Mobile. In the Class Battery, get percentage of the charge in the battery. In class Mobile, check the battery percentage and display the following message. If battery percentage == 0 Print “Phone is switched Off” Else if battery percentage lies between 5 to 20. Print “Please charge your phone” Else Print “No need of charging”
  • 15. import java.util.Scanner; class Battery { int percentage; public Battery(int percentage) { this.percentage=percentage; } } public class Mobile { Battery bt; Mobile(Battery bt) { this .bt = bt; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 16. public static void main(String args[]) { Scanner sc = new Scanner(System.in); int percentage = sc.nextInt(); Battery bt = new Battery(percentage); Mobile lenova = new Mobile(bt); if(lenova.bt.percentage == 0) { System.out.print("Phone is switched Off"); } else if((5 <= lenova.bt.percentage)&& (lenova.bt.percentage<=20) ) { System.out.print("Please charge your phone"); } else { System.out.print("No need of charging"); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Editor's Notes

  1. 1st slide (Mandatory)
  2. Section End/Start Use this at section’s start or end. For example: “Questions” or “Time for Practice”. To be used for Impacts (get the student’s attention).
  3. Question+ Input + Output (Programming)
  4. Question+ Input + Output (Programming)
  5. Input + Output (Programming) (After slide 19)
  6. Question+ Input + Output (Programming)
  7. Question+ Input + Output (Programming)
  8. Thank you slide