Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////// LAB 2 OOP HELALI APA //////////////////
- // TASK 2
- ----------------------------------------------------------------------------------------
- public class BankAccount {
- public String name, ID;
- public double balance;
- public BankAccount (String name , String ID, double balance){
- this.name=name;
- this.ID=ID;
- this.balance=balance;
- } // Constructor
- // Method One
- public void deposit(double depAmount){
- balance = balance + depAmount;
- }
- //Method Two
- public void withdraw(double withAmount){
- if (balance >= withAmount){
- balance = balance - withAmount;
- }
- else {
- System.err.println("Insufficient balance for withdraw");
- }
- }
- //Method Three
- public double getBalance(){
- return balance;
- }
- //Method Four
- public void display() {
- System.out.println("Name:" + name + " ID: " + ID + " Balance: " + balance);
- }
- }
- public class Bank{
- public static void main (String [] args){
- BankAccount cus1 = new BankAccount();
- cus1.name = "Nadira Anjum";
- cus1.ID = "120053";
- cus1.balance = 0;
- cus1.deposit(1000);
- cus1.withdraw(3000);
- System.out.println(cus1.getBalance());
- cus1.display();
- }
- }
- public class BankAccountArray {
- public static void main (String [] args){
- BankAccount[] customer = new BankAccount[4];
- customer [0] = new BankAccount("Nazrul Islam" ,"1234" ,20000 );
- customer [1] = new BankAccount("Rizvi Mahmud", "2345", 2000);
- customer [2] = new BankAccount("Rizwana Khan", "3456" , 3000);
- customer [3] = new BankAccount( "Anwar Hossain","4567" , 1000 );
- for (int i =0; i<customer.length; i++){
- customer[i].display();
- }
- }
- }
- ----------------------------------------------------END----------------------------------------------
- ------------------------------------------------------------------------------------------------------
- //TASK 3 (a) OPTION 1
- package com.company;
- import java.util.Scanner;
- public class Fibo {
- public static void main(String[] args) {
- int t1 =0, t2 = 1, nextTerm = 0;
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter the term");
- int n = scan.nextInt();
- for (int i= 1; i<=n ; ++i){
- if (i == 1){
- System.out.printf(" %d " , t1);
- continue;
- }
- if (i == 2){
- System.out.printf(" %d " , t2);
- continue;
- }
- nextTerm = t1 + t2;
- t1 = t2;
- t2 = nextTerm;
- System.out.printf(" %d " , nextTerm);
- }
- }
- }
- //TASK 3(b) OPTION 1
- package com.company;
- import java.util.Scanner;
- public class EvenOdd {
- public static void main(String args[]) {
- Scanner input = new Scanner(System.in);
- System.out.printf("Enter any number : ");
- int number = input.nextInt();
- if ((number % 2) == 0) {
- System.out.printf("number %d is even number %n", number);
- } else {
- System.out.printf("number %d is odd number %n", number);
- }
- }
- }
- ---------------------------------------------------------------------------------------------------------------
- PROBLEM 3 ... OPTION 2
- public class Numbers {
- int num;
- public void showFibonacci() {
- int t1 = 0, t2 = 1, nextTerm = 0;
- for (int i = 1; i <= num; ++i) {
- if (i == 1) {
- System.out.printf(" %d ", t1);
- continue;
- }
- if (i == 2) {
- System.out.printf(" %d ", t2);
- continue;
- }
- nextTerm = t1 + t2;
- t1 = t2;
- t2 = nextTerm;
- System.out.printf(" %d ", nextTerm);
- }
- }
- public void showPyramid(){
- int rowCount = 1;
- System.out.println("Here Is the Pyramid");
- if (num <=9 ) {
- for (int i = num; i > 0; i--) {
- for (int j = 1; j <= i * 2; j++) {
- System.out.print(" ");
- }
- for (int j = 1; j <= rowCount; j++) {
- System.out.print(j + " ");
- }
- for (int j = rowCount - 1; j >= 1; j--) {
- System.out.print(j + " ");
- }
- System.out.println();
- rowCount++;
- }
- }
- else { /////// ***** You can avoid this else part for printing *****//////
- for (int i = 9; i > 0; i--) {
- for (int j = 1; j <= i * 2; j++) {
- System.out.print(" ");
- }
- for (int j = 1; j <= rowCount; j++) {
- System.out.print(j + " ");
- }
- for (int j = rowCount - 1; j >= 1; j--) {
- System.out.print(j + " ");
- }
- System.out.println();
- rowCount++;
- }
- }
- }
- public boolean checkNumber(){
- boolean even = true;
- if (num%2!=0){
- even = false;
- }
- return true;
- }
- void setNum(int num){
- }
- }
- import java.util.Scanner;
- public class NumberTest {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Numbers test = new Numbers();
- int select = sc.nextInt();
- test.num = 5;
- switch (select) {
- case 1:test.showFibonacci();
- break;
- case 2:test.showPyramid();
- break;
- case 3: test.checkNumber();
- break;
- case 4:test.setNum(0);
- }
- }
- }
- ---------------------------------------------------------------------------E---N----D-------------------------------------------------
Add Comment
Please, Sign In to add comment