Posts

slip 25

1.... import java.io.* ; class Except { public static void main(String args[])throws Exception { InputStreamReader r=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(r); System.out.println(“Enter name:”); String name = br.readLine(); System.out.println(“Enter roll no.:”); String number=br.readLine(); System.out.println(“Enter marks:”); String marks=br.readLine(); System.out.println(“name:”+name); System.out.println(“Roll No.:”+number); System.out.println(“Marks:”+marks); } } 2. import javax.swing.*; import java.awt.*; import java.awt.event.*; class seta3 extends JFrame implements ActionListener {  private JLabel l1,l2,l3;  private JButton b;  private JRadioButton r1,r2,r3;  private JCheckBox c1,c2,c3;  private JTextField t1,t2;  private ButtonGroup b1;  private JPanel p1,p2;1  private StringBuffer s1=new StringBuffer();  public seta3(String s)  {   super(s);   b1=new ButtonGroup();   p1=new JPanel(); ...

slip No.17

1. import java.util.Scanner; class Customer {  String name;  String phoneNumber;  void readCustomer(Scanner sc) {  System.out.print("Enter Customer Name: ");  name = sc.nextLine();  System.out.print("Enter Phone Number: ");  phoneNumber = sc.nextLine();  }  void displayCustomer() {  System.out.println("Customer Name : " + name);  System.out.println("Phone Number : " + phoneNumber);  } } class Depositor extends Customer {  String accno; double balance;  void readDepositor(Scanner sc) {  readCustomer(sc);  System.out.print("Enter Account Number: ");  accno = sc.nextLine();  System.out.print("Enter Balance: ");  balance = sc.nextDouble();  sc.nextLine(); // consume newline  }  void displayDepositor() {  displayCustomer();  System.out.println("Account Number : " + accno);  System.out.println("Balance : " + balance);  } } class Borro...

slip.16

1. import java.util.Scanner; @FunctionalInterface interface Square {  int calculate(int x); } public class SquareUsingInterface {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in); Square s = (int x) -> x * x;  System.out.print("Enter a number: ");  int num = sc.nextInt();    int result = s.calculate(num);  System.out.println("Square of " + num + " is: " + result);  sc.close();  } } 2. import java.awt.*; import java.awt.event.*; public class AWTMenuExample {  Frame frame;  public AWTMenuExample() {  frame = new Frame("Java AWT Examples");    MenuBar menuBar = new MenuBar();    Menu fileMenu = new Menu("File");  MenuItem newItem = new MenuItem("New", new MenuShortcut(KeyEvent.VK_N));   MenuItem openItem = new MenuItem("Open"); MenuItem saveItem = new MenuItem("Save");  CheckboxMenuItem showAbout = new CheckboxMenuItem("Show Ab...

slip.14

1. import java.util.Scanner; class ZeroException extends Exception {  public ZeroException(String message) {  super(message);  } } public class PrimeCheck {    public static boolean isPrime(int n) {  if (n <= 1) return false;  for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) return false;  }  return true;  }  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.print("Enter a number: ");  int num = sc.nextInt();  try {  if (num == 0) {  throw new ZeroException("Number is 0");  }  if (isPrime(num)) {  System.out.println(num + " is a prime number.");  } else {  System.out.println(num + " is not a prime number.");  }  } catch (ZeroException e) {  System.out.println("Exception: " + e.getMessage());  } finally {  sc.close();  }  } } 2. Step 1: Package SY File: SY/S...

slip No.11

1. import java.util.Scanner; interface Operation {  double PI = 3.142;   double volume();  } class Cylinder implements Operation {  private double radius;  private double height;    public Cylinder(double radius, double height) {  this.radius = radius;  this.height = height;  }  public double volume() {  return PI * radius * radius * height;  } } public class CylinderDemo {  public static void main(String[] args) { Scanner sc = new Scanner(System.in);  System.out.print("Enter radius of cylinder: ");  double r = sc.nextDouble();  System.out.print("Enter height of cylinder: ");  double h = sc.nextDouble();  Cylinder cylinder = new Cylinder(r, h);  System.out.println("Volume of the cylinder: " + cylinder.volume());  sc.close();  } } 2. import java.util.Scanner; class InvalidPasswordException extends Exception {  public InvalidPasswordException(S...

slip.10

1. import java.util.Scanner; @FunctionalInterface interface CubeCalculator {  int cube(int n); } public class CubeFunctionalInterface {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.print("Enter a number: ");  int num = sc.nextInt();  CubeCalculator cubeCalc = n -> n * n * n;  int result = cubeCalc.cube(num);  System.out.println("Cube of " + num + " is: " + result);  sc.close();  } } 2. Step 1: Create package student File: StudentInfo.java package student; public class StudentInfo {  private int rollNo;  private String name;  private String className;  private double percentage;    public StudentInfo(int rollNo, String name, String className, double percentage) {  this.rollNo = rollNo;  this.name = name;  this.className = className;  this.percentage = percentage;  }    public void display() { ...

slip.8

1. import java.util.Scanner; class Sphere {  private double radius;    public Sphere(double radius) {  this.radius = radius;  }    public double surfaceArea() {  return 4 * Math.PI * radius * radius; }    public double volume() {  return (4.0 / 3.0) * Math.PI * radius * radius * radius;  }    public void display() {  System.out.println("Radius of Sphere: " + radius);  System.out.println("Surface Area : " + surfaceArea());  System.out.println("Volume : " + volume());  } } public class SphereTest {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.print("Enter radius of the sphere: ");  double r = sc.nextDouble();  Sphere sphere = new Sphere(r);  sphere.display();  sc.close();  } } 2. import java.awt.*; import java.awt.event.*; public class MouseEventDemo extends Frame implements MouseListen...