Basic Program using Class
1. Create a class BankAccount that has Depositor name , Acc_no, Acc_type, Balance as Data Members and void createAcc() . void Deposit(), void withdraw() and void BalanceInquiry as Member Function. When a new Account is created assign next serial no as account number. Account number starts from 1package com.company;import java.util.Scanner;public class bank {String depositorname;int Acc_no;String acc_type;double balance;static int flag=0;Scanner sc=new Scanner(System.in);bank(){createaccount();}void createaccount (){Acc_no=++flag;System.out.println("enetr depositor name");depositorname=sc.nextLine();System.out.println("enter account type");acc_type=sc.nextLine();balance=sc.nextDouble();}void withdraw (){System.out.println("enter how much amount you wat to withdraw");double ammount= sc.nextDouble();balance=balance-ammount;System.out.println(ammount+"is debited from your bank tremaining bakalnce is "+balance);}void deposite (){System.out.println("enter how much amount you wat to deposite");double ammount= sc.nextDouble();balance=balance+ammount;System.out.println(ammount+"is credit from your bank remaning balance is "+balance);}void balanceinquiry (){System.out.println(depositorname);System.out.println(Acc_no);System.out.println(acc_type);System.out.println(balance);}}public class Main {public static void main(String[] args) {bank b1=new bank();bank b2=new bank();bank b3=new bank();b1.withdraw();b1.balanceinquiry();b2.deposite();b2.balanceinquiry();b3.balanceinquiry();}}
2. Create a class time that has hour, minute and second as data members. Create a parameterized constructor to initialize Time Objects. Create a member Function Time Sum (Time, Time) to sum two time objects.
package com.company;public class TIME {int hour;int min;int sec;TIME(int hour,int min,int sec){this.hour=hour;this.min=min;this.sec=sec;}TIME (){}TIME sum2objects (TIME a){TIME ret=new TIME();ret.hour=this.hour+a.hour;ret.min=this.min+a.min;ret.sec=this.sec+a.sec;if(ret.sec >59){ret.min++;ret.sec-=60;}if(ret.min >59){ret.hour++;ret.min-=60;}return ret;}}public class Main {public static void main(String[] args) {TIME t1=new TIME(4,34,56);TIME t2=new TIME(2,30,59);TIME t3=t2.sum2objects(t1);System.out.println(t3.hour+" : "+t3.min +" : "+ t3.sec);}}
DA is 74% of Basic Salary for all. Use appropriate member function
package com.company;public class salary {String name;double salary;double dearnessallowance;salary (String name,int salary){this.name=name;this.salary=salary;this.dearnessallowance=0.74*salary;}double tds () {if (salary + dearnessallowance <= 100000) {return 0;} else {return salary + dearnessallowance * 0.10;}}void printeverything (){System.out.println("name: "+name);System.out.println("basic salary: "+salary);System.out.println("tds: "+tds());System.out.println("dearness allowance: "+dearnessallowance);System.out.println("net salary: "+ (salary+dearnessallowance-tds()));}}public class Main {public static void main(String[] args){salary s=new salary("vedantraval" ,2500000);s.printeverything();}}
0 Comments