write java program to create a class call person with nage and age attribute create
two instance of the person class set their attributes using constructed and print
their name and age
ANS:
import java.util.*;
class person{
String name;
int age;
public person(String name,int age){
this.name = name;
this.age = age;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("enter your Name: ");
String name = sc.nextLine();
System.out.println("enter your age: ");
int age = sc.nextInt();
person person = new person(name,age);
System.out.println("Name: "+person.name);
System.out.println("age: "+person.age);
}
}
write a java program to create aclass cale book with attributes for title,uthor and
ISBN also create method to add and remove books
ANS:
import java.util.*;
class Book{
String title;
String author;
int isbl;
public Book(String title,String author,int isbl){
this.title = title;
this.author = author;
this.isbl=isbl;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("enter title Of the book: ");
String title = sc.nextLine();
System.out.println("enter author of the book: ");
String author= sc.nextLine();
System.out.println("enter isbl: ");
int isbl = sc.nextInt();
Book book = new Book(title, author,isbl);
System.out.println("title: "+book.title);
System.out.println("author: "+book.author);
System.out.println("ISBL: "+book.isbl);
}
}
public remove element("book"){
write a java program tocreate a class employee with name joitle and salary
attributes and methods to calculate and update the salary