Posts

Showing posts from November, 2023

Slip22

 Q1) Write a program to create an abstract class named Shape that contains two integers and an empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contain only the method printArea() that prints the area of the given shape. (use method overriding). [10 marks]  import java.util.*; abstract class shape {    int x,y;    abstract void area(double x,double y); } class Rectangle extends shape { void area(double x,double y) {     System.out.println("Area of rectangle is :"+(x*y)); } } class Circle extends shape { void area(double x,double y) {    System.out.println("Area of circle is :"+(3.14*x*x)); } } class Triangle extends shape { void area(double x,double y) {    System.out.println("Area of triangle is :"+(0.5*x*y)); } } public class Slip22_1 {   public static void main(String[...

Slip21

 Q1) Define a class MyDate(Day, Month, year) with methods to accept and display a MyDateobject. Accept date as dd,mm,yyyy. Throw user defined exception "InvalidDateException" if the date is invalid. [10 marks]  class InvalidDateException extends Exception  {     public InvalidDateException() {         System.out.println("Given Date is Invalid");     } } class MyDate  {     int day,month,year;     public MyDate(int day, int month, int year)      {         try {     if (isValidDate(day, month, year)) {             this.day = day;             this.month = month;             this.year = year;     System.out.println("Valid Date: "+day+"/"+month+"/"+year);         } else              throw new InvalidDateExcept...

Slip20

 Q1) Write a Program to illustrate multilevel Inheritance such that country is inherited from continent. State is inherited from country. Display the place, state, country and continent. [10 marks]  import java.io.*; class Continent {    String con;     BufferedReader r  = new BufferedReader(new InputStreamReader(System.in));     void con_input() throws IOException  {        System.out.println("Enter Continent Name:  ");         con = r.readLine();      } } class Country extends Continent {  String cou ;  void cou_input() throws IOException  {        System.out.println("Enter Country Name:  ");        cou = r.readLine();      }  }   class State extends Country {  String sta,place;  void sta_input() throws IOException  {        System.out.p...

Slip19

Q1) Write a program to accept the two dimensional array from user and display sum of its diagonal elements. [10 marks]  import java.util.*; public class Slip19_1 {    public static void main(String[] args)  { Scanner sc=new Scanner(System.in); System.out.println("Enter size of the matrix "); int r=sc.nextInt(); int c=sc.nextInt();       int[][] m = new int[r][c];       int sum=0;       System.out.println("Enter the matrix elements : ");       for (int i = 0; i < r; i++)  {          for (int j = 0; j < c; j++)   { m[i][j]=sc.nextInt(); if(i==j) sum+=m[i][j];    } }         System.out.println(" The sum of diagonal elements of the matrix is: " + sum);    }   } Q2) Write a program which shows the combo box which includes list of T.Y.B.Sc.(Comp. Sci) subjects. Display the selected subject in a...

Slip18

 Q1) Write a program to implement Border Layout Manager. [10 marks]   import java.awt.*; import java.awt.event.*; public class BorderLayoutExample  {   public static void main(String[] args)  {   Frame frame= new Frame("BorderLayout Frame");         frame.setLayout(new BorderLayout(10,10)); Button b1=new Button("NORTH");   frame.add(b1, BorderLayout.NORTH);   frame.add(new Button("SOUTH"), BorderLayout.SOUTH);   frame.add(new Button("EAST"), BorderLayout.EAST);   frame.add(new Button("WEST"), BorderLayout.WEST);   frame.add(new Button("CENTER"), BorderLayout.CENTER);   frame.setSize(300,300);   frame.setVisible(true);   } } Q2) Define a class CricketPlayer (name,no_of_innings,no_of_times_notout, totatruns, bat_avg). Create an array of n player objects. Calculate the batting average for each player using static method avg(). Define a static sort method which sorts the array on the basi...

Slip17

 Q1) Design a Super class Customer (name, phone-number). Derive a class Depositor(accno , balance) from Customer. Again, derive a class Borrower (loan-no, loan-amt) from Depositor. Write necessary member functions to read and display the details of ‘n’customers. [10 marks]  import java.util.*; class Customer  {    String cname;    int pno;    Customer(String cname,int pno)   {        this.cname=cname; this.pno=pno;    } void display()   {        System.out.println("Customer Name: "+cname+"\nPhone No: "+pno);          } } class Depositor extends Customer  {    int accno , balance;    Depositor(String cname,int pno,int accno, int  balance)   {         super(cname,pno); this.accno=accno;   this.balance=balance;  } void display()   { super.di...

Slip 16

Q1) Write a program to find the Square of given number using function interface. [10 marks]  //slip16_1 //@FunctionalInterface interface PrintNumber { public void print(int num1); } public class PrintSquare { public static void main(String[] a) { PrintNumber p = n -> System.out.println("Square is: "+ n*n); p.print(25); } } Q2) Write a program to design a screen using Awt that, [20 marks] import java.awt.*;   class Slip16_2 extends Frame   {          Slip16_2()         {              setLayout(new FlowLayout());     MenuBar mb=new MenuBar();               Menu menuFile = new Menu("File");              Menu menuEdit = new Menu("Edit");              Menu menuView = new Menu("About");      MenuItem  m1= new MenuItem ("New");  ...

Slip15

 Q1) Accept the names of two files and copy the contents of the first to the second. First file having Book name and Author name in file. [10 marks]  import java.io.*; public class SetA3_Copy  { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter Source file name"); String f1=br.readLine(); System.out.println("Enter Destination file name"); String f2=br.readLine(); FileReader in = new FileReader(f1); FileWriter out = new FileWriter(f2); int c; while ((c=in.read()) != -1) out.write(c); out.write("\nEnd of file"); in.close(); out.close(); FileReader fr = new FileReader(f2); while ((c=fr.read()) != -1) System.out.print((char)c); } } Q2) Write a program to define a class Account having members custname, accno. Define default and parameterized constructor. Create a subclass called SavingAccount with member savingbal, minbal. Create a derived class Ac...

Slip14

 Q1) Write a program to accept a number from the user, if number is zero then throw user defined exception “Number is 0” otherwise check whether no is prime or not (Use static keyword). [10 marks]  //Slip14_1 import java.util.*; class NumberException extends Exception {    NumberException()   {        System.out.println("Number is 0");  } } class Slip14_1 {  public static void main( String args[] )  {   Scanner sc=new Scanner(System.in); System.out.println("Enter Number "); int n=sc.nextInt(); try { if(n==0) throw new NumberException(); else { int i,m=0,flag=0;         m=n/2;         if(n==0||n==1)       System.out.println(n+" is not prime number");         else {       for(i=2;i<=m;i++) {           if(n%i==0) ...

Slip13

 Q1) Write a program to accept a file name from command prompt, if the file exits then display number of words and lines in that file. [10 marks]  import java.io.*; class Slip13_1 { public static void main(String args[]) throws IOException { String line,dirname=args[0]; int ch,i,cnt=0,lcnt=0; File f1=new File(dirname); if(f1.isFile() && f1.exists()) { BufferedReader br = new BufferedReader(new FileReader(f1));             while((line = br.readLine()) != null)  {   lcnt++;             String words[] = line.split("");                   cnt = cnt + words.length;   } } System.out.println("Total Number Of Lines:"+lcnt); System.out.println("Total Number Of Words:"+cnt); } } Q2) Write a program to display the system date and time in various formats shown below: Current date is : 31/08/2...

Slip12

 Q1) Write a program to create parent class College(cno, cname, caddr) and derived class Department(dno, dname) from College. Write a necessary methods to display College details. [10 marks]  import java.util.*; class College {    String cname, caddr;    int cno;    College(int cno, String cname, String caddr)   {        this.cno=cno;   this.cname=cname; this.caddr=caddr;  } void display()   {        System.out.println("College No: "+cno+"\nCollege Name: "+cname+"\nCollege Address: "+caddr);          } } class Department extends College {    String dname;    int dno;    Department(int cno, String cname, String caddr,int dno, String dname)   {        super(cno,cname,caddr); this.dno=dno;   this.dname=dname;  } void display()   { super.display(); ...

Slip11

 Q1) Define an interface “Operation” which has method volume( ).Define a constant PI having a value 3.142 Create a class cylinder which implements this interface (members – radius,height). Create one object and calculate the volume. [10 marks]  //slip 11_1 interface operation {        static double PI=3.14;        double area();        double volume(); } class Cylinder implements operation {         int rad;         int height;          Cylinder(int rad,int height)         {                 this.rad=rad;                 this.height=height;           }         public double  area()         {                 System.out.print("\nArea of Cylinde...

Slip 10

 Q1) Write a program to find the cube of given number using functional interface. [10 marks]  //@FunctionalInterface interface PrintNumber { public void print(int num1); } public class Slip10_1 { public static void main(String[] a) { PrintNumber p = n -> System.out.println("Cube is: "+ n*n*n); p.print(5); } } Q2) Write a program to create a package name student. Define class StudentInfo with method to display information about student such as rollno, class, and percentage. Create another class StudentPer with method to find percentage of the student. Accept student details like rollno, name, class and marks of 6 subject from user. [20 marks] //StudentInfo.java package student; public class StudentInfo { public void display_student(int r,String n, String c,double p)  {     System.out.println ("Roll No. = "+r);    System.out.println ("Name = "+n);    System.out.println ("Class = "+c);    System.out.println ("Percentage = "+p+...

Slip9

 Q1) Define a “Clock” class that does the following ; a. Accept Hours, Minutes and Seconds b. Check the validity of numbers c. Set the time to AM/PM mode Use the necessary constructors and methods to do the above task [10 marks]  import java.util.*; class Clock {    int hr,min,sec; //store hours    public Clock (int hr, int min, int sec)     {       this.hr=hr; this.min=min; this.sec=sec;    }    public boolean checktime()     { boolean hflag,mflag,sflag;       if (hr>=0 && hr < 24) hflag=true;         else hflag=false; if (min >=0 && min < 60)           mflag=true;         else mflag=false;       if (sec >=0 && sec < 60)           sflag=true;         else sflag=false; if(hflag...