Você está na página 1de 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

COURIER & ATM ASSIGNMENT

HARPREET SINGH BTACCS-08063 TRU# 9571906

COMP-266, SEM- 4 Gurinder Singh Duggal 6th October, 2010

Page 1 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

Courier Service
Main Class
pacckage courierservice; public class Main { public static void main(String[] args) { Express express=new Express(); Regular regular=new Regular(); Premium premium=new Premium(); Courier courier= premium; System.out.println(courier.getCost(12)); System.out.println(courier.getTime()); System.out.println(courier.getRatePerKG()); } }

Regular:

pacckage courierservice; public class Regular implements Courier {

Page 2 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

public int getRatePerKG(){ return RatePerKG; } public int getCost(int weight){ return (RatePerKG)*weight; } public int getTime(){ return 5; } }

Express:

pacckage courierservice; public class Express implements Courier { public int getRatePerKG(){ return RatePerKG*2; } public int getCost(int weight){ return (RatePerKG*2)*weight; } public int getTime(){
Page 3 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

return 3; } }

Premium:

pacckage courierservice; public class Premium implements Courier { public int getRatePerKG(){ return RatePerKG*3; } public int getCost(int weight){ return (RatePerKG*3)*weight; } public int getTime(){ return 1; } }

Pacckage and Interfacce

pacckage courierservice; interfacce Courier {


Page 4 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

final public int RatePerKG=20; public int getRatePerKG(); public int getCost(int weight); public int getTime();

Page 5 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

ATM MACCHINE
class Customers{ public String Name; public int accc_no,pin,balance; } class Deposit{ public int deposit(int a, int b) { return a+b; } } class Withdraw{ public int withdraw(int a, int b) { return b-a; }

Page 6 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

} class Display{ void dislay(String a, int b) { System.out.println("Name" +a); System.out.println("Balance" +b); } } import java.io.*; public class Main { public static void main(String[] args)throws IOException { InputStreamReader i= new InputStreamReader(System.in); BufferedReader br= new BufferedReader(i); Customer cust[]=new Customer[2]; Deposit dep = new Deposit(); Withdraw wid=new Withdraw(); Display s = new Display(); int x,accc,pin,balance,choice,dep,wid,ch;
Page 7 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

for(x=0; x<=1; x++) { cust[x]=new Customer(); System.out.print("Enter Name"); cust[x].Name=br.Readline(); System.out.print("Enter Acccount Number"); cust[x].accc=Integer.parseInt(br.Readline()); System.out.print("Enter Acccount Number"); cust[x].pin=Integer.parseInt(br.Readline()); System.out.print("Enter Acccount Number"); cust[x].balance=Integer.parseInt(br.Readline()); } System.out.println("Your Info Has Been Stored"); System.out.print("Enter 1. to continue enter 2. to Exit"); ch=Integer.parseInt(br.Readline());

Page 8 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

do { System.out.println("Enter Your Acccount Number"); acc=Integer.parseInt(br.Readline()); for (x = 0; x <= 1; x++) { if(acc==c[x].acc){ System.out.println("Enter Your Pin Number"); pn=Integer.parseInt(br.Readline()); if(pin==c[x].pin) { System.out.println("Welcome to Your Acccount"); System.out.println("Press 1 for deposit Press 2 for withdraw Press 3 for Display"); choice=Integer.parseInt(br.readline()); switch(choice){

case 1: System.out.print("Enter Amount to Deposit");


Page 9 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

dep=Integer.parseInt(br.readline()); balance=d.deposit(dep,cust[x].balance); cust[x].balance=balance; break; case 2: System.out.print("Enter Amount to Withdraw"); wid=Integer.parseInt(br.readline()); balance=w.withdraw(wid,cust[x].balance); cust[x].balance=balance; break; case 3: s.dislay(cust[x].Name, cust[x].balance); break; default: System.out.print("Invalid Input"); } } Else
Page 10 of 11

JAVA ASSIGNMENT HARPREET SINGH TRU#9571906

{ System.out.print("Info Didn't Match"); } } } }while(ch!=2); } }

Page 11 of 11

Você também pode gostar