Monday, 21 November 2022

Inheritance Exercise 1 - infosys

 Inheritance Exercise 1 - infosys

Inheritance Exercise 1 - infosys,infosys assignment quiz and lex genrric ansewer,coding savior,infosys generic java program,code monk,coding bar,code saviour,code answer,code solution for infosys  assignmenet,code saviour trend, Two classes - Camera and Digital Camera are provided to you.  Though the object of DigitalCamera class is being created with values as 'Canon' and 100 in the main method of Tester class, the code given below generates the following output.        Make the necessary changes in the code such that the member variables are initialized with proper values and the output is generated as follows:  Output








class Camera {
    private String brand;
    private double cost;

    public Camera() {
        this.brand = "Nikon";
    }
    public Camera(String brand,double cost){
    this.brand=brand;
    this.cost=cost;
    }
    public String getBrand() {
        return brand;
    }
    public void setBrand(String brand) {
        this.brand = brand;
    }
    public double getCost() {
        return cost;
    }
    public void setCost(double cost) {
        this.cost = cost;
    }
}

class DigitalCamera extends Camera {
    private int memory;

    public DigitalCamera(String brand, double cost) {
   
        super(brand,cost);
        this.memory = 16;
    }
   
    public int getMemory() {
        return memory;
    }
    public void setMemory(int memory) {
        this.memory = memory;
    }
}

class Tester {
    public static void main(String[] args) {
        DigitalCamera camera = new DigitalCamera("Canon",100);
        System.out.println(camera.getBrand()+" "+camera.getCost()+" "+camera.getMemory());
    }
}

                        
Inheritance Exercise 1 - infosys,infosys assignment quiz and lex genrric ansewer,coding savior,infosys generic java program,code monk,coding bar,code saviour,code answer,code solution for infosys  assignmenet,code saviour trend,


Sunday, 20 November 2022

Association - Exercise 1

 

Association - Exercise 1


You need to develop an application for cab service providers by implementing the classes based on the class diagram and description given below.    Note: Driver class is provided to you.  Method Description  CabServiceProvider  CabServiceProvider(String cabServiceName, int totalCabs)  Initialize all the instance variables appropriately with the values passed to the constructor. calculateRewardPrice(Driver driver)  Calculate and return the bonus of the driver based on the below table. If averageRating of the driver is less than 4, return the bonus as 0.                  In case of any invalid value, return the bonus as 0.  Note: Round off the bonus to 2 decimal digits.  Implement the appropriate getter and setter methods.  Perform case-sensitive comparison wherever applicable.  Test the functionalities using the provided Tester class.      Sample Input and Output  Input  For CabServiceProvider object cabServiceProvider1 with cabServiceName = Halo and totalCabs = 50  Driver object - driver1    Driver object - driver2    Driver object - driver3    Output,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



class CabServiceProvider{
private static final String String=null;
private String cabServiceName;
private int totalCabs;
public CabServiceProvider(String cabServiceName,int totalCabs){
this.cabServiceName=cabServiceName;
this.totalCabs=totalCabs;
}
public String getCabServiceName(){
return cabServiceName;
}
public void setCabServiceName(String cabServiceName){
this.cabServiceName=cabServiceName;
}
public int getTotalCabs(){
return totalCabs;
}
public  void setTotalCabs(int totalCabs){
this.totalCabs=totalCabs;
}
public double calculateRewardPrice(Driver driver){
double bonus=0.0;
double rewardAmount=0.0;
if(cabServiceName.equals("Halo")){
if(driver.getAverageRating()>=4.5&&driver.getAverageRating()<=5){
rewardAmount=10*driver.getAverageRating();
}
else if(driver.getAverageRating()>=4&&driver.getAverageRating()<4.5){
rewardAmount=5*driver.getAverageRating();
}
else{
rewardAmount=0.0;
}
}
else if(cabServiceName.equals("Aber")){
if(driver.getAverageRating()>=4.5&&driver.getAverageRating()<=5){
rewardAmount=8*driver.getAverageRating();
}
else if(driver.getAverageRating()>=4&&driver.getAverageRating()<4.5){
rewardAmount=3*driver.getAverageRating();
}
else{
rewardAmount=0.0;
}
}
else{
rewardAmount=0.0;
}
bonus=Math.round(rewardAmount*100.0)/100.0;
return bonus;
}
}

class Driver {
   
    private String driverName;
    private float averageRating;
   
    public Driver(String driverName, float averageRating){
        this.driverName=driverName;
        this.averageRating=averageRating;
    }
   
    public String getDriverName(){
        return this.driverName;
    }
   
    public void setDriverName(String driverName){
        this.driverName=driverName;
    }
   
    public float getAverageRating(){
        return this.averageRating;
    }
   
    public void setAverageRating(float averageRating){
        this.averageRating=averageRating;
    }

    //DO NOT MODIFY THE METHOD
    //Your exercise might not be verified if the below method is modified
    public String toString(){
        return "Driver\ndriverName: "+this.driverName+"\naverageRating: "+this.averageRating;
    }
}

class Tester {
   
    public static void main(String args[]){
        CabServiceProvider cabServiceProvider1 = new CabServiceProvider("Halo", 50);

        Driver driver1 = new Driver("Luke", 4.8f);
        Driver driver2 = new Driver("Mark", 4.2f);
        Driver driver3 = new Driver("David", 3.9f);
       
        Driver[] driversList = { driver1, driver2, driver3 };
        for (Driver driver : driversList) {
            System.out.println("Driver Name: "+driver.getDriverName());
            double bonus = cabServiceProvider1.calculateRewardPrice(driver);
            if (bonus>0)
                System.out.println("Bonus: $"+bonus+"\n");
            else
                System.out.println("Sorry, bonus is not available!");
        }
       
        //Create more objects of CabServiceProvider and Driver classes for testing your code
    }
}

You need to develop an application for cab service providers by implementing the classes based on the class diagram and description given below.    Note: Driver class is provided to you.  Method Description  CabServiceProvider  CabServiceProvider(String cabServiceName, int totalCabs)  Initialize all the instance variables appropriately with the values passed to the constructor. calculateRewardPrice(Driver driver)  Calculate and return the bonus of the driver based on the below table. If averageRating of the driver is less than 4, return the bonus as 0.                  In case of any invalid value, return the bonus as 0.  Note: Round off the bonus to 2 decimal digits.  Implement the appropriate getter and setter methods.  Perform case-sensitive comparison wherever applicable.  Test the functionalities using the provided Tester class.      Sample Input and Output  Input  For CabServiceProvider object cabServiceProvider1 with cabServiceName = Halo and totalCabs = 50  Driver object - driver1    Driver object - driver2    Driver object - driver3    Output


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





Association - Exercise 1

 Association - 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 , You need to develop an application for cab service providers by implementing the classes based on the class diagram and description given below.    Note: Driver class is provided to you.  Method Description  CabServiceProvider  CabServiceProvider(String cabServiceName, int totalCabs)  Initialize all the instance variables appropriately with the values passed to the constructor. calculateRewardPrice(Driver driver)  Calculate and return the bonus of the driver based on the below table. If averageRating of the driver is less than 4, return the bonus as 0.                  In case of any invalid value, return the bonus as 0.  Note: Round off the bonus to 2 decimal digits.  Implement the appropriate getter and setter methods.  Perform case-sensitive comparison wherever applicable.  Test the functionalities using the provided Tester class.      Sample Input and Output  Input  For CabServiceProvider object cabServiceProvider1 with cabServiceName = Halo and totalCabs = 50  Driver object - driver1    Driver object - driver2    Driver object - driver3    Output





























class CabServiceProvider{
private static final String String=null;
private String cabServiceName;
private int totalCabs;
public CabServiceProvider(String cabServiceName,int totalCabs){
this.cabServiceName=cabServiceName;
this.totalCabs=totalCabs;
}
public String getCabServiceName(){
return cabServiceName;
}
public void setCabServiceName(String cabServiceName){
this.cabServiceName=cabServiceName;
}
public int getTotalCabs(){
return totalCabs;
}
public  void setTotalCabs(int totalCabs){
this.totalCabs=totalCabs;
}
public double calculateRewardPrice(Driver driver){
double bonus=0.0;
double rewardAmount=0.0;
if(cabServiceName.equals("Halo")){
if(driver.getAverageRating()>=4.5&&driver.getAverageRating()<=5){
rewardAmount=10*driver.getAverageRating();
}
else if(driver.getAverageRating()>=4&&driver.getAverageRating()<4.5){
rewardAmount=5*driver.getAverageRating();
}
else{
rewardAmount=0.0;
}
}
else if(cabServiceName.equals("Aber")){
if(driver.getAverageRating()>=4.5&&driver.getAverageRating()<=5){
rewardAmount=8*driver.getAverageRating();
}
else if(driver.getAverageRating()>=4&&driver.getAverageRating()<4.5){
rewardAmount=3*driver.getAverageRating();
}
else{
rewardAmount=0.0;
}
}
else{
rewardAmount=0.0;
}
bonus=Math.round(rewardAmount*100.0)/100.0;
return bonus;
}
}

class Driver {
   
    private String driverName;
    private float averageRating;
   
    public Driver(String driverName, float averageRating){
        this.driverName=driverName;
        this.averageRating=averageRating;
    }
   
    public String getDriverName(){
        return this.driverName;
    }
   
    public void setDriverName(String driverName){
        this.driverName=driverName;
    }
   
    public float getAverageRating(){
        return this.averageRating;
    }
   
    public void setAverageRating(float averageRating){
        this.averageRating=averageRating;
    }

    //DO NOT MODIFY THE METHOD
    //Your exercise might not be verified if the below method is modified
    public String toString(){
        return "Driver\ndriverName: "+this.driverName+"\naverageRating: "+this.averageRating;
    }
}

class Tester {
   
    public static void main(String args[]){
        CabServiceProvider cabServiceProvider1 = new CabServiceProvider("Halo", 50);

        Driver driver1 = new Driver("Luke", 4.8f);
        Driver driver2 = new Driver("Mark", 4.2f);
        Driver driver3 = new Driver("David", 3.9f);
       
        Driver[] driversList = { driver1, driver2, driver3 };
        for (Driver driver : driversList) {
            System.out.println("Driver Name: "+driver.getDriverName());
            double bonus = cabServiceProvider1.calculateRewardPrice(driver);
            if (bonus>0)
                System.out.println("Bonus: $"+bonus+"\n");
            else
                System.out.println("Sorry, bonus is not available!");
        }
       
        //Create more objects of CabServiceProvider and Driver classes for testing your code
    }
}

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 , You need to develop an application for cab service providers by implementing the classes based on the class diagram and description given below.    Note: Driver class is provided to you.  Method Description  CabServiceProvider  CabServiceProvider(String cabServiceName, int totalCabs)  Initialize all the instance variables appropriately with the values passed to the constructor. calculateRewardPrice(Driver driver)  Calculate and return the bonus of the driver based on the below table. If averageRating of the driver is less than 4, return the bonus as 0.                  In case of any invalid value, return the bonus as 0.  Note: Round off the bonus to 2 decimal digits.  Implement the appropriate getter and setter methods.  Perform case-sensitive comparison wherever applicable.  Test the functionalities using the provided Tester class.      Sample Input and Output  Input  For CabServiceProvider object cabServiceProvider1 with cabServiceName = Halo and totalCabs = 50  Driver object - driver1    Driver object - driver2    Driver object - driver3    Output





Array - Exercise 1 , Calculate and return the sum of all the even numbers present in the numbers array passed to the method calculateSumOfEvenNumbers. Test the functionalities using the main() method of the Tester class.

 Array - Exercise 1


Calculate and return the sum of all the even numbers present in the numbers array passed to the method calculateSumOfEvenNumbers. Implement the logic inside calculateSumOfEvenNumbers() method.  Test the functionalities using the main() method of the Tester class.     Sample Input and Output








class Tester{
public static int calculateSumOfEvenNumbers(int[]numbers){
int sum=0;
for(int i=0;i<numbers.length;i++)
{
int a=numbers[i]%2;
if(a==0)
{
sum=sum+numbers[i];
}
}
returnsum;
}
public static void main(String[]args){
int[]numbers={68,79,86,99,23,2,41,100};
System.out.println("Sum of even numbers: "+calculateSumOfEvenNumbers(numbers));
}
}



String - Exercise 1

 String - Exercise 1


Complete the removeWhiteSpaces() method given in the Tester class.

Method Description

removeWhiteSpaces(String str)

  • Remove all the white spaces from the string passed to the method and return the modified string.

Test the functionalities using the main() method of the Tester class. 

 

Sample Input and Output


class Tester{

public static String removeWhiteSpaces(String str){
String noSpaceStr=str.replaceAll("\\s","");//usingbuiltinmethod
//Implementyourcodehereandchangethereturnvalueaccordingly
return noSpaceStr;
    }
   
    public static void main(String args[]){
        String str = "Hello   How are you   ";
        str = removeWhiteSpaces(str);
        System.out.println(str);
    }
}

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




Encapsulation - Exercise 1

 Encapsulation - Exercise 1


Problem Statement

Consider the class Employee given below for representing employees of an organization. It has 5 different instance variables and a method to calculate the total salary based on the jobLevel.

Salary is calculated in the calculateSalary() method.

Make necessary changes to the class by making all the attributes private and by adding necessary accessor and mutator methods thus bringing in Encapsulation.



class Employee {

 String employeeId;
 String employeeName;
 int salary;
 int bonus;
int jobLevel;
public String getEmployeeId(){
return employeeId;
}
public void setEmployeeId(String employeeId){
this.employeeId=employeeId;
}
public String getEmployeeName(){
return employeeName;
}
public void setEmployeeName(String employeeName){
this.employeeName=employeeName;
}
public int getSalary(){
return salary;
}
public void setSalary(int salary){
this.salary=salary;
}
public int getBonus(){
return bonus;
}
public void setBonus(int bonus){
this.bonus=bonus;
}
public int getJobLevel(){
return jobLevel;
}
public void setJobLevel(int jobLevel){
this.jobLevel=jobLevel;
}

    public void calculateSalary() {
        if (this.jobLevel >= 4) {
            this.bonus = 100;
        } else {
            this.bonus = 50;
        }
        this.salary += this.bonus;
    }
}

class Tester {

    public static void main(String args[]) {

        Employee employee = new Employee();
        employee.employeeId = "C101";
        employee.employeeName = "Steve";
        employee.salary = 650;
        employee.jobLevel = 4;

        employee.calculateSalary();

        System.out.println("Employee Details");
        System.out.println("Employee Id: " + employee.employeeId);
        System.out.println("Employee Name: " + employee.employeeName);
        System.out.println("Salary: " + employee.salary);

    }
}










Saturday, 19 November 2022

Methods - Assignment 3

 

Methods - Assignment 3

Implement a class Calculator with the instance variable and method mentioned below. 

Method Description

sumOfDigits()

  • Calculate and return the sum of the digits of the num member variable

Test the functionalities using the provided Tester class. 

 

Sample Input and Output

class Calculator{
public int num;
public int sumOfDigits()
{
int a=num,rem=0,sum=0;
while(a!=0)
{
rem=a%10;
a=a/10;
sum=sum+rem;
}
return sum;
}
}
class Tester{
public static void main(String args[]){
     Calculator calculator=new Calculator();
calculator.num=123;
int x=calculator.sumOfDigits();
System.out.println(x);
//AssignavaluetothemembervariablenumofCalculatorclass//InvokethemethodsumOfDigitsofCalculatorclassanddisplaytheoutput}
}
}





Methods - Exercise 1

Methods - Exercise 1

 Implement a class Calculator with the method mentioned below. 

Method Description

findAverage()

  • Calculate the average of three numbers

  • Return the average rounded off to two decimal digits
    ​​​​

Test the functionalities using the provided Tester class. 

 

Sample Input and Output

 

Hint:  For round-off to two decimal digits:

double num1 = 65, num2 = 175;
double num3 = num1/num2;
System.out.println(Math.round(num3*100.0)/100.0);


class Calculator{
public double findAverage(int number1,int number2,int number3){
double sum=(number1+number2+number3);
double average=sum/3;
double roundoff=Math.round(average*100.0)/100.0;
return roundoff;
}
}
class Tester{
public static void main(String args[]){
Calculator calculator= new Calculator();
double x=calculator.findAverage(12,8,15);
System.out.println(x);
//InvokethemethodfindAverageoftheCalculatorclassanddisplaytheaverage}
}
}









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 ...