0% found this document useful (0 votes)
18 views

201 Assignment 1

The document defines two Java classes: Book and Person. The Book class contains fields for a book's title, author, ISBN, page count, and price. It includes getter and setter methods for each field. The Person class contains fields for a person's first name, last name, age, and gender. It also includes getter and setter methods for each field. The main method creates instances of the Book and Person classes and calls their getter methods to retrieve field values.

Uploaded by

danyalhamzah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

201 Assignment 1

The document defines two Java classes: Book and Person. The Book class contains fields for a book's title, author, ISBN, page count, and price. It includes getter and setter methods for each field. The Person class contains fields for a person's first name, last name, age, and gender. It also includes getter and setter methods for each field. The main method creates instances of the Book and Person classes and calls their getter methods to retrieve field values.

Uploaded by

danyalhamzah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

EXERCISE1

Public class Book {

String title;

String author;

String isbn;

Int pagecount;

Double price;

Public Book(String title, String author, String isbn, Int pagecount, Double price) {

this.title = title;

this.author = author;

this.isbn = isbn;

this.pagecount = pagecount;

this.price = price;

Public String getTitle() {

return title;

Public void setTitle(String title) {

This.title = title;

Public String getAuthor() {

return author;

Public void setAuthor(String author) {

This.author = author;

Public String getISBN() {

Return ISBN;

}
Public void setISBN(String isbn) {

This.isbn = isbn;

Public int getpageCount() {

Return pagecount;

Public void setpageCount(Int pagecount) {

This.pagecount = pagecount;

Public Double getPrice() {

Return price;

Public void setPrice(double price) {

This.price = price;

Public static void main(String[] args) {

Book book1 = new Book(Samuel,Cronicles,abcd,70,50.4);

book1.getTitle();

book1.getAuthor();

book1.getISBN();

book1.getpageCount();

book1.getPrice();

Book book2 = new Book (John,Alpha,efgh,80,40.6);

book2.getTitle();

book2.getAuthor();

book2.getISBN();
book2.getpageCount();

Book book3 = new Book (James,School,ijkl,90,60.8);

book3.getTitle();

book3.getAuthor();

book3.getISBN();

book3.getpageCount();

book3.getPrice();

Public class Person {

String firstName;

String lastName;

Int age;

String gender;

Public Person(String firstName, String lastName, int age, String gender,) {

this.firstName = firstName

this.lastName = lastName;

this.age = age;

this.gender = gender;

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 int getAge() {

Return age;

Public void setAge(int age) {

This.age = age;

Public String getGender() {

Return gender;

Public void setGender(String gender) {

This.gender = gender;

Public static void main(String[] args) {

Person person1 = new Person(Samuel,Arthur,25,male);

person1.getfirstName();
person1.getlastName();

person1.getAge();

person1.getGender();

Person person2 = new Person(Alpha,Blondy,100,male);

Person2.getfirstName();

Person2.getlastName();

Person2.getAge();

Person2.getGender();

Person person3 = new Person(Danyal,Hamza,22,male);

Person3.getfirstName();

Person3.getlastName();

Person3.getAge();

Person3.getGender();

You might also like