code2pdf_6741f6dfb17a2
code2pdf_6741f6dfb17a2
// Simple(){
// }
// }
// void setNum1(double num1){
// this.num1 = num1;
// }
// double getNum1(){
// return num1;
// }
// double getNum2(){
// return num2;
// }
// void add(){
// System.out.println("Number1 + Number2 :"+ (num1+num2));
// }
// void mul(){
// System.out.println("Number1 * Number2 :"+ num1*num2);
// }
// void div(){
// System.out.println("Number1 / Number2 :"+ num1/num2);
// }
// void sub(){
// System.out.println("Number1 - Number2 :"+ (num1-num2));
// }
// }
// VerifiedSimple(){
// super();
// }
// void add(){
// super.add();
// }else{
// System.out.println("Both numbers shoulb be greater than zero.");
// }
// }
// void sub(){
// super.sub();
// }else{
// System.out.println("Both numbers shoulb be greater than zero.");
// }
// }
// void mul(){
// super.mul();
// }else{
// System.out.println("Both numbers shoulb be greater than zero.");
// }
// }
// void div(){
// super.div();
// }else{
// System.out.println("Both numbers shoulb be greater than zero.");
// }
// }
// }
// s1.add();
// s1.sub();
// s1.mul();
// s1.div();
// s2.setNum1(10);
// s2.setNum2(10);
// s2.add();
// s2.mul();
// s2.div();
// s2.sub();
// }
// }
// }
// void m1(){
// System.out.println("M1");
// }
// }
// class Two extends One{
// void m2(){
// System.out.println("M2");
// }
// void m3(){
// System.out.println("M3");
// }
// }
// class Main{
// public static void main(String[] args) {
// Two t1 = new Two();
// t1.m1();
// t1.m2();
// t1.m3();
// }
// }
// Shapes() {
// this.noOfLines = 0;
// this.penColor = "Black";
// this.fillColor = "White";
// }
// Rectangle(){
// super();
// }
// }
// Square(){
// super();
// }
// }
// Circle(){
// super();
// }
// }
// class Main{
// public static void main(String[] args) {
// s3.setNoOfLines(10);
// s3.setFillColor("Orange");
// s3.setPenColor("Orange");
// s3.draw();
// }
// }
// class Shape{
// void draw(){
// System.out.println("I am in Shape");
// }
// }
// void draw(){
// System.out.println("I am in circle");
// }
// void circle(){
// System.out.println("Circle");
// }
// }
// void draw(){
// System.out.println("I am in Square");
// }
// void square(){
// System.out.println("Square");
// }
// }
// void draw(){
// System.out.println("I am in Rectangle");
// }
// void rectangle(){
// System.out.println("Rectangle");
// }
// }
// class Main{
// public static void main(String[] args) {
// }
// }
// class OverFlow {
// public static void test(int i) {
// if (i == 0)
// return;
// else {
// System.out.println(i);
// test(i++);
// }
// }
// }
// class Exception {
// public static void main(String[] args) {
// OverFlow.test(5);
// }
// }
// class Exception{
// static int divideByZero(int a, int b) {
// int i = a / b;
// return i;
// }
// System.out.println(computeDivision(10, 0));
// }
// }
// class throwException {
// }
// }
// }
// class Exception {
// public static void main(String[] args) {
// try{
// throwException.fun();
// }catch(NullPointerException e){
// System.out.println("Caught in main");
// System.out.println(e.getMessage());
// }
// }
// }
// class Exception{
// public static void main(String[] args) {
// int a = 10 ;
// int b = 0 ;
// try{
// int c = a/b;
// System.out.println(c);
// }catch(ArithmeticException e){
// System.out.println(e.getMessage());
// }
// String s = null;
// try{
// System.out.println(s.length());
// }catch(NullPointerException e){
// System.out.println(e.getMessage());
// }
// String c = "abc";
// try{
// int d = Integer.parseInt(c);
// System.out.println(d);
// }catch(NumberFormatException e){
// System.out.println(e.getMessage());
// }
// try{
// array[11] = 12;
// }catch(ArrayIndexOutOfBoundsException e){
// System.out.println(e.getMessage());
// }
// }
// }
// MyException(String str1){
// this.str1= str1;
// }
// class Exception{
// public static void main(String[] args) {
// try{
// System.out.println("In try block.");
// throw new MyException("My Exception.");
// }catch(MyException exp){
// System.out.println("In catch block.");
// System.out.println(exp);
// }
// }
// }
//One Practice Program
// try {
// System.out.println("Initial balance: $" + account.getBalance());
// } catch (InvalidAmountException e) {
// System.out.println("Error: " + e.getMessage());
// }
// try {
// // Test valid withdrawal
// account.withdraw(100.00);
// System.out.println("Balance after withdrawal: $" + account.getBalance());
// } catch (InsufficientFundsException e) {
// System.out.println("Error: " + e.getMessage());
// } catch (InvalidAmountException e) {
// System.out.println("Error: " + e.getMessage());
// }
// try {
// // Test invalid withdrawal (negative amount)
// account.withdraw(-50.00); // This should throw InvalidAmountException
// } catch (InsufficientFundsException e) {
// System.out.println("Error: " + e.getMessage());
// } catch (InvalidAmountException e) {
// System.out.println("Error: " + e.getMessage());
// }
// }
// }
// Circle(){
// }
// @Override
// public int compareTo(Circle c){
// if(this.radius> c.radius){
// return 1;
// }
// else if(this.radius < c.radius){
// return -1;
// }else{
// return 0;
// }
// }
// Circle(int radius ){
// this.radius = radius;
// }
// int getRadius(){
// retur radius;
// }
// int calculateArea(){
// return 3.14*radius*radius;
// }
// }
// class Main{
// public static void main(String[] args) {
// System.out.println(c1.compareTo(c2));
// }
// }
//Cloneable
// int radius;
// Circle() {
// }
// Circle(int radius) {
// this.radius = radius;
// }
// void display() {
// System.out.println("Radius is: " + radius);
// }
// @Override
// protected Object clone() throws CloneNotSupportedException {
// return super.clone();
// }
// }
// try {
// Circle c2 = (Circle) c1.clone();
// c2.display();
// } catch (CloneNotSupportedException e) {
// e.printStackTrace();
// }
// }
// }
// CloneAble Pratice
// }
// Circle(int radius){
// this.radius = radius;
// }
// void display(){
// System.out.println("Radius is :" + radius);
// }
// @Override
// protected Object clone() throws CloneNotSupportedException{
// return super.clone();
// }
// }
// public class Main {
// try{
// Circle c2 = (Circle) c1.clone();
// c2.display();
// }catch(CloneNotSupportedException e){
// System.out.println(e.getMessage());
// }
// }
// }
// import java.util.ArrayList;
// class Main{
// public static void main(String[] args) {
// arrayList.add(0);
// arrayList.add(1);
// arrayList.add(2);
// arrayList.add(3);
// arrayList.add(5);
// System.out.println(arrayList);
// arrayList.remove(4);
// System.out.println(arrayList);
// arrayList.set(0, 5);
// System.out.println(arrayList);
// System.out.println(arrayList.size());
// System.out.println(arrayList.get(0));
// }
// }
// Custom Exceptions
// class CheckedException extends Exception{
// CheckedException(){
// }
// CheckedException(String message){
// super(message);
// }
// }
// class BankAccount {
// protected double balance;
// public BankAccount() {}
// public SavingAccount() {
// super();
// }
// @Override
// public void withdraw(double amount) throws CheckedException {
// if (super.getBalance() - amount < minimumBalance) {
// throw new MinimumBalanceException("Cannot withdraw below the minimum balance.");
// }
// super.withdraw(amount);
// }
// }
// public CurrentAccount() {
// super();
// }
// @Override
// public void withdraw(double amount) throws CheckedException {
// if (super.getBalance() - amount < -overdraftLimit) {
// throw new OverdraftLimitExceedException("Cannot withdraw beyond the overdraft limit.");
// }
// System.out.println("Current Account");
// System.out.println("Current Account Balance :" + super.balance);
// super.withdraw(amount);
// }
// }
// public class Main {
// public static void main(String[] args) {
// BankAccount b1 = new BankAccount(100000.0);
// try {
// b1.withdraw(3400);
// } catch (InsufficientFundsException e) {
// System.out.println(e.getMessage());
// }catch (CheckedException e) {
// System.out.println(e.getMessage());
// }
// class Employee {
// protected int id;
// protected String name;
// protected double salary;
// Employee() {}
// double calculateBonus(){
// return (0.1)*salary;
// }
// void printDetails(){
// System.out.println("ID :" + id + ", Name :"+ name + ", Salary :"+ salary);
// System.out.println("Bonus :" +this.calculateBonus());
// }
// }
// Manager(){
// super();
// }
// Manager(int id, String name, double salary, int teamSize) throws CheckedExceptions{
// super(id, name, salary);
// if(teamSize<0){
// throw new InvalidTeamSizeException("Invalid team size.");
// }
// this.teamSize = teamSize;
// }
// int getTeamSize(){
// return teamSize;
// }
// Developer(){
// super();
// }
// Developer(int id, String name, double salary, int linesOfCode) throws CheckedExceptions{
// super(id, name, salary);
// if(linesOfCode<0){
// throw new InvalidCodeCountException("Invalid Code lines.");
// }
// this.linesOfCode = linesOfCode;
// }
// }
// int getLinesOfCode(){
// return linesOfCode;
// }
// void printDetails(){
// super.printDetails();
// }
// }
// public class Main{
// public static void main(String[] args) {
// try{
// Employee e1 = new Employee(411989, "umer", 10000);
// System.out.println("Employee Details");
// e1.printDetails();
// }catch(InvalidSalaryException e){
// System.out.println(e.getMessage());
// }catch(CheckedExceptions e){
// System.out.println(e.getMessage());
// }
// try{
// Manager m1 = new Manager(512345, "Talha", 20000, 12);
// System.out.println("Manager Details");
// m1.printDetails();
// }catch(InvalidTeamSizeException e){
// System.out.println(e.getMessage());
// }catch(CheckedExceptions e){
// System.out.println(e.getMessage());
// }
// try{
// Developer d1 = new Developer(512345, "Talha", 25000, 1600);
// System.out.println("Developer Details");
// d1.printDetails();
// }catch(InvalidCodeCountException e){
// System.out.println(e.getMessage());
// }catch(CheckedExceptions e){
// System.out.println(e.getMessage());
// }
// }
// }
// PaymentMethod(){
// }
// PaymentMethod(double amount){
// this.amount = amount;
// }
// String getPaymentDetails(){
// return "Amount :" + amount;
// }
// }
// CreditCard(){
// super();
// }
// CreditCard(double amount,String creditCardNumber, String expiryDate){
// super(amount);
// this.creditCardNumber = creditCardNumber;
// this.expiryDate = expiryDate;
// }
// void processPayment(){
// System.out.println("Payment through credit card.");
// }
// String getPaymentDetails(){
// System.out.println("Credit Card");
// return super.getPaymentDetails() + ", Credit card number :" + creditCardNumber + ", Expiry date :"+ expiryDate;
// }
// }
// PayPal(){
// super();
// }
// PayPal(double amount, String email){
// super(amount);
// this.email = email;
// }
// void processPayment(){
// System.out.println("Payment through paypal.");
// }
// String getPaymentDetails(){
// System.out.println("PayPal");
// return super.getPaymentDetails() + ", Email :" + email;
// }
// }
// void processPayment(){
// System.out.println("Payment through bank transfer.");
// }
// String getPaymentDetails(){
// System.out.println("Bank Transfer");
// return super.getPaymentDetails() + ", Bank account number :" + bankAccountNumber + ", Bank name : "+ bankName;
// }
// }
// class Main{
// public static void main(String[] args) {
// }
// }
// import javax.swing.*;
// import java.awt.*;
// import java.awt.event.*;
// import java.util.ArrayList;
// class Student {
// private String st_name;
// private int st_id;
// String getName() {
// return st_name;
// }
// int getId() {
// return st_id;
// }
// @Override
// public String toString() {
// return "Name: " + st_name + ", ID: " + st_id;
// }
// }
// public StudentManagerGUI() {
// studentList = new ArrayList<>();
// initUI();
// }
// if (name.isEmpty() || idText.isEmpty()) {
// JOptionPane.showMessageDialog(frame, "Please fill in both fields.", "Error", JOptionPane.ERROR_MESSAGE);
// return;
// }
// try {
// int id = Integer.parseInt(idText);
// if (id < 0) {
// throw new NumberFormatException("ID must be positive.");
// }
// studentList.add(new Student(name, id));
// nameField.setText("");
// idField.setText("");
// updateStudentList();
// } catch (NumberFormatException ex) {
// JOptionPane.showMessageDialog(frame, "ID must be a valid positive number.", "Error", JOptionPane.ERROR_MESSAGE);
// }
// });
// frame.setVisible(true);
// }
// import java.util.*;
// class Student {
// private String name;
// private int id;
// Student() {}
// Student(String name, int id) {
// this.name = name;
// this.id = id;
// }
// void display() {
// System.out.println("Name: " + name);
// System.out.println("ID: " + id);
// }
// String getName() {
// return name;
// }
// int getId() {
// return id;
// }
// class Main {
// public static Student createStudent(Scanner scanner, int count) {
// int id;
// String name;
// if (students.remove(targetStudent)) {
// System.out.println("Successfully removed the student.");
// if (!students.isEmpty()) {
// System.out.println("Updated Student List:");
// displayStudents(students);
// } else {
// System.out.println("The student list is now empty.");
// System.out.print("Would you like to add new students (yes or no)? ");
// String response = scanner.nextLine();
// if (response.equalsIgnoreCase("yes")) {
// int count = 1;
// do {
// students.add(createStudent(scanner, count));
// System.out.print("Add another student (yes/no)? ");
// response = scanner.nextLine();
// count++;
// } while (response.equalsIgnoreCase("yes"));
// } else {
// System.out.println("Operation complete.");
// }
// }
// } else {
// System.out.println("No matching student found.");
// }
// }
// do {
// students.add(createStudent(scanner, count));
// System.out.print("Would you like to add another student (yes or no)? ");
// response = scanner.nextLine();
// count++;
// } while (response.equalsIgnoreCase("yes"));
// if (proceed.equalsIgnoreCase("yes")) {
// String action;
// String exitChoice;
// do {
// System.out.println("Available Actions:");
// System.out.println("1. Enter 'remove' to delete a student");
// System.out.println("2. Enter 'display' to view all students");
// action = scanner.nextLine();
// if (action.equalsIgnoreCase("remove")) {
// if(!students.isEmpty()){
// removeStudent(scanner, students);
// }else{
// System.out.println("No Students to display");
// }
// } else if (action.equalsIgnoreCase("display")) {
// if(!students.isEmpty()){
// displayStudents(students);
// }else{
// System.out.println("No Students to display");
// }
// } else {
// System.out.println("Invalid input. Please try again.");
// }
// scanner.close();
// }
// }