Posts

Showing posts from October, 2023

Slip 8

 Q1) Create a class Sphere, to calculate the volume and surface area of sphere. (Hint : Surface area=4*3.14(r*r), Volume=(4/3)3.14(r*r*r)) import java.util.*; public class sphere_Slip8_1 {           public static void main(String args[])       {       int radius;       //double pie=3.14285714286;   Scanner s=new Scanner(System.in); System.out.println("Enter the Radious"); radius=s.nextInt(); double area=4*(Math.PI)*radius*radius;   System.out.println("Area of the sphere="+area);     double volume=(4.0/3.0)*Math.PI*(radius*radius*radius);       System.out.println("Volume of the sphere="+volume);        }   }   Q2) Design a screen to handle the Mouse Events such as MOUSE_MOVED and MOUSE_CLICKED and display the position of the Mouse_Click in a TextField. import java.awt.*; import jav...

Slip 7

 Q1) Design a class for Bank. Bank Class should support following operations; a. Deposit a certain amount into an account b. Withdraw a certain amount from an account c. Return a Balance value specifying the amount with details [10 marks]  import java.io.*; class Bank {     int acno;     String name;     double balance;           public Bank(int ano,String n,double b)     {         acno=ano; name=n; balance=b;     }         public void viewBalance()    { System.out.println("Account Number : " +acno );         System.out.println("Name: " + name);             System.out.println("The balance is: " + balance);     }       public void deposit(double amount)    {     ...

Slip6

 Q1) Write a program to display the Employee(Empid, Empname, Empdesignation, Empsal) information using toString(). [10 marks]  class Employee {    int Empid,Empsal;  String Empname,Empdesg;       Employee(int Empid,String Empname,String Empdesg,int Empsal){    this.Empid=Empid;    this.Empname=Empname;    this.Empdesg=Empdesg;   this.Empsal=Empsal;  }    public String toString() {  return Empid+"\t "+Empname+"\t "+Empdesg+"\t "+Empsal;       }  }   class Slip6_1 { public static void main(String args[]) {      Employee s1=new Employee(101,"abc","Manager",20000);      Employee s2=new Employee(102,"def","Fitter",12000);       System.out.println("Roll No   Name Designation Salary");       System.out.println(s1);    System.out.print...

Slip 5

 Q1) Write a program for 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.println("...

Slip4

  Q1) Write a program to print an array after changing the rows and columns of a given two-dimensional array. [10 marks]  import java.util.Scanner; public class Slip4_1{ public static void main(String[] args)  { int[][] twodm = { {10, 20, 30}, {40, 50, 60} }; System.out.print("Original Array:\n"); print_array(twodm); int[][] newtwodm = new int[twodm[0].length][twodm.length]; for (int i = 0; i < twodm.length; i++)  for (int j = 0; j < twodm[0].length; j++)  newtwodm[j][i] = twodm[i][j]; System.out.println("After changing the rows and columns of the said array:"); print_array(newtwodm); } static void print_array(int[][] twodm)  { for (int i = 0; i < twodm.length; i++)  { for (int j = 0; j < twodm[0].length; j++)  { System.out.print(twodm[i][j] + " "); } System.out.println(); } } }  Q2) Write a program to design...

Slip3

Q1 ) Write a program to accept ‘n’ name of cities from the user and sort them in ascending order. [10 marks] import java.util.Scanner; public class Slip3_1 {     public static void main(String[] args)      {         int n;         String temp;         Scanner s = new Scanner(System.in);         System.out.print("Enter number of names you want to enter:");         n = s.nextInt();         String names[] = new String[n];         Scanner s1 = new Scanner(System.in);         System.out.println("Enter all the names:");         for(int i = 0; i < n; i++)              names[i] = s1.nextLine();         for (int i = 0; i < n; i++)          {             for (...

Slip2

 Q1) Write a program to read the First Name and Last Name of a person, his weight and height using command line arguments. Calculate the BMI Index which is defined as the individual's body mass divided by the square of their height. (Hint : BMI = Wts. In kgs / (ht)2)  import java.util.Scanner; public class Slip2_1 {     public static void main(String[] args)      {         double wt, ht; String fname,lname; fname=args[0]; lname=args[1]; wt=Double.parseDouble(args[2]); ht=Double.parseDouble(args[3]); double bmi=wt/(ht*ht);         System.out.println("Person Name : "+fname+" "+lname);         System.out.println("BMI : "+bmi);     } }  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 m...

Slip1

 Q1.  Write a Program to print all Prime numbers in an array of ‘n’ elements. (use command line arguments) import java.util.Scanner; public class Slip1_1 {      public static void main (String[] args)      {                int n=Integer.parseInt(args[0]);                boolean[] isPrime=new boolean[n];               int[] ar = new int [n];               Scanner in = new Scanner (System.in);               System.out.println("Enter the "+n+" elements of the array: ");               for(int i=0; i<n; i++)                  ar[i] = in.nextInt();               for(int i=0; i<ar.length; i++)   ...