Posts

Showing posts from October, 2024

Slip30

Image
 Q1) Write program to define class Person with data member as Personname,Aadharno, Panno. Accept information for 5 objects and display appropriate information (use this keyword). [10 marks]  import java.util.Scanner; class Person {     String personName, aadharNo, panNo;         public Person(String personName, String aadharNo, String panNo)          {         this.personName = personName;          this.aadharNo = aadharNo;              this.panNo = panNo;                }     public String toString()      {         System.out.println("Person Name: " + this.personName);         System.out.println("Aadhar Number: " + this.aadharNo);         System.out.println("PAN Number: " + this.panNo);        return...

Slip29

 Q1) Write a program to create a class Customer(custno,custname,contactnumber,custaddr). Write a method to search the customer name with given contact number and display the details. [10 marks]  import java.util.*; class Customer  {     int custno;     String custname,contactnumber,custaddr;     public Customer(int custno, String custname, String contactnumber, String custaddr) {         this.custno = custno;         this.custname = custname;         this.contactnumber = contactnumber;         this.custaddr = custaddr;     }     public void displayDetails()      {         System.out.println("Customer Number: " +  custno);         System.out.println("Customer Name: " + custname);         System.out.println("Contact Number: " + contactnumber);     ...

Slp28

 Q1) Write a program that reads on file name from the user, then displays information about whether the file exists, whether the file is readable, whether the file is writable, the type of file and the length of the file in bytes. [10 marks]  import java.io.File; import java.util.Scanner; public class Slip28_1 {     public static void main(String[] args)      {         Scanner scanner = new Scanner(System.in);         System.out.print("Enter the file name (with full path): ");         String fileName = scanner.nextLine();         File file = new File(fileName);         if (file.exists())  {             System.out.println("File exists.");             System.out.println("Readable: " + file.canRead());             System.out.println("Writable: " + file.canW...

Slp27

 Q1) Define an Employee class with suitable attributes having getSalary() method, which returns salary withdrawn by a particular employee. Write a class Manager which extends a class Employee, override the getSalary() method, which will return salary of manager by adding traveling allowance, house rent allowance etc. [10 marks] class Employee {     String name;     double salary;     public Employee(String name, double salary) {         this.name = name;         this.salary = salary;     }     public double getSalary() {         return salary;     } } class Manager extends Employee {     double ta,ha;          public Manager(String name, double salary, double ta,double ha){         super(name, salary);         this.ta = ta;         this.ha = ha;     }   ...

Slip26

 Q1) Define a Item class (item_number, item_name, item_price). Define a default and parameterized constructor. Keep a count of objects created. Create objects using parameterized constructor and display the object count after each object is created.(Use static member and method). Also display the contents of each object. [10 marks]  class Item {     int ino;     String iname;     double iprice;     static int count = 0;     public Item()      {         count++;     }     public Item(int ino, String iname, double iprice)      {         this.ino = ino;         this.iname = iname;         this.iprice = iprice;       count++;     }     public static int getObjectCount()      {         return count;     }    ...

Slip25

Image
 Q1) Create a class Student(rollno, name ,class, per), to read student information from the console and display them (Using BufferedReader class) [10 marks] import java.io.*; class Student_25_1  {     int rollno;     String name,studentClass;     double percentage;     public Student_25_1(int rollno, String name, String studentClass, double percentage)      {         this.rollno = rollno;         this.name = name;         this.studentClass = studentClass;         this.percentage = percentage;     }     public String toString()      {         System.out.println("Student Details:");         System.out.println("Roll No: " + rollno);         System.out.println("Name: " + name);         System.out.println("Class: " + studentClass); ...

Slip24

Image
 Q1) Create an abstract class 'Bank' with an abstract method 'getBalance'. Rs.100, Rs.150 and Rs.200 are deposited in banks A, B and C respectively. 'BankA', 'BankB' and 'BankC' are subclasses of class 'Bank', each having a method named 'getBalance'. Call this method by creating an object of each of the three classes. [10 marks]  abstract class Bank {      abstract int getBalance(); } class BankA extends Bank  {  private int balance;  void deposit(int money)  { balance += money;  }   int getBalance()   {      return balance;  } } class BankB extends Bank { private int balance; void deposit(int money)          { balance += money;       }        int getBalance()         {          return balance;         } } class BankC extends Bank  {    privat...

Slip23

Image
 Q1) Define a class MyNumber having one private int data member. Write a default constructor to initialize it to 0 and another constructor to initialize it to a value (Use this). Write methods isNegative, isPositive, isZero, isOdd, isEven. Create an object in main.Use command line arguments to pass a value to the Object. [10 marks]  class MyNumber { private int no; MyNumber() { no=5; } MyNumber(int no) { this.no=no; } public void isNegative() { if(no<0) System.out.println("Given number is negative"); } public void isPositive() { if(no>0) System.out.println("Given number is Positive"); } public void isZero() { if(no==0) System.out.println("Given number is Zero"); } public void isOdd() { if(no%2!=0) System.out.println("Given number is Odd"); } public void isEven() { if(no%2==0) System.out.println("Given      is Even"); }  public static void main(String args[])  { MyNumber n1=new MyNumber(); System.out.println(n1.no+" Deta...