Sunday, 20 November 2022

Static - Exercise 1 infosys

 

Static - Exercise 1

coding savior,infosys assignment quiz and lex genrric ansewer,infosys generic java program, code answer,code saviour,code monk,coding bar,code solution for infosys  assignmenet,code saviour trend , Implement the class Bill based on the class diagram and description given below.    Method Description  Bill(String paymentMode)  Initialize the paymentMode instance variable with the value passed to the parameter.   Generate the billId using counter. The value of billId should start from 'B9001' and the numerical part should be incremented by 1 for the subsequent values. Initialize the counter in static block.  Implement the appropriate getter and setter methods.     Test the functionalities using the provided Tester class. Create two or more Bill objects and validate that the billId is being generated properly.  Sample Input and Output  For constructor  Input  For first Bill object    For second Bill object    Output





























class Bill{
private static int counter;
private String billId;
private String paymentMode;
static{
counter=9000;
}
public Bill(String paymentMode){
this.paymentMode=paymentMode;
billId="B"+ ++counter;
}
public static int getCounter(){
return counter;
}
public String getBillId(){
return billId;
}
public  void setBillId(String billId){
this.billId=billId;
}
public String getPaymentMode(){
return paymentMode;
}
public void setPaymentMode(String paymentMode){
this.paymentMode=paymentMode;
}

}

class Tester {
    public static void main(String[] args) {

        Bill bill1 = new Bill("DebitCard");
        Bill bill2 = new Bill("PayPal");
        Bill bill3=new Bill("CreditCard");
        Bill bill4=new Bill("PayTm");
        Bill bill5=new Bill("GooglePay");
       
        //Create more objects and add them to the bills array for testing your code
             
        Bill[] bills = { bill1, bill2, bill3, bill4, bill5};
             
        for (Bill bill : bills) {
            System.out.println("Bill Details");
            System.out.println("Bill Id: " + bill.getBillId());
            System.out.println("Payment method: " + bill.getPaymentMode());
            System.out.println();
       }
    }
}
Bill Details Bill Id: B9001 Payment method: DebitCard  Bill Details Bill Id: B9002 Payment method: PayPal  Bill Details Bill Id: B9003 Payment method: CreditCard  Bill Details Bill Id: B9004 Payment method: PayTm  Bill Details Bill Id: B9005 Payment method: GooglePay





No comments:

Post a Comment

Free Resume Template

Creating a blog post that discusses the pros and cons of using a resume rule is a great way to provide valuable information to job seekers ...