Ticket program

Page 1

GS311 Java Lab

package smcard;

/** * * @author dell */ public class Smcard {

/** * @param args the command line arguments */ public static void main(String[] args) {

credit mycredit= new credit("john","robin",374598,600.0,4000,"Credit",12345); debit mydebit= new debit("john","robin",374598,600.0,0.0,"Credit",12345);


System.out.printf("firstname:%s\n lastname:%s\n passport:%d\n ticket:%f\n balance:%f\n balance after purchase:%.2f\n", mycredit.firstname,mycredit.lastname,mycredit.passport,mycredit.tic ket,mycredit.balance,mycredit.ticketprice()); System.out.printf("firstname:%s\n lastname:%s\n passport:%d\n ticket:%f\n balance:%f\n balance after purchase:%.2f\n", mydebit.firstname,mydebit.lastname,mydebit.passport,mydebit.ticke t,mydebit.balance,mydebit.ticketprice());

} } package smcard;

/** * * @author dell */ public class card { String firstname; String lastname; int passport; double ticket;


double balance; public card(String f,String l,int p,double t,double b) { firstname=f; lastname=l; passport=p; ticket=t; balance=b; } public void setfirt(String f) { firstname=f; } public String getfirst() { return firstname; } public void setlast(String l) { lastname=l; }


public String getlast() { return lastname; } public void setpass(int p) { passport=p; } public int getpass() { return passport; } public void setticket(double t) { ticket=t; } public double getticket() { return ticket; }


public void setbalance(double b) { balance=b; } public double getbalance() { return balance; } public double ticketprice() { return balance-ticket; }

} public class credit extends card { String cardname; int cardnum; public credit(String f,String l,int p,double t,double b,String c,int cnum) { super(f,l,p,t,b);


cardname=c; cardnum=cnum; } public void setcardname(String c) { cardname=c; } public String getcardname() { return cardname; } public void setcardnum(int cnum) { cardnum=cnum; } public int getcardnum() { return cardnum; } public double ticketprice() {


return super.ticketprice(); }

} public class credit extends card { String cardname; int cardnum; public credit(String f,String l,int p,double t,double b,String c,int cnum) { super(f,l,p,t,b); cardname=c; cardnum=cnum; } public void setcardname(String c) { cardname=c; } public String getcardname() {


return cardname; } public void setcardnum(int cnum) { cardnum=cnum; } public int getcardnum() { return cardnum; } public double ticketprice() { return super.ticketprice(); }

} public class debit extends card { String cardname; int cardnum;


public debit(String f,String l,int p,double t,double b,String c,int cnum) { super(f,l,p,t,b); cardname=c; cardnum=cnum; } public void setcardname(String c) { cardname=c; } public String getcardname() { return cardname; } public void setcardnum(int cnum) { cardnum=cnum; } public int getcardnum() { return cardnum;


} public double ticketprice() { double t =super.ticketprice(); if(balance>0.0) balance=t; else System.out.println("Error"); return t; }

}


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.