Showing posts with label infosys tranning solution. Show all posts
Showing posts with label infosys tranning solution. Show all posts

Saturday, 19 November 2022

selection Control Structure - Assignment 4

 Selection Control Structure - Assignment 4

Implement a program to calculate the product of three positive integer values. However, if one of the integers is 7, consider only the values to the right of 7 for calculation. If 7 is the last integer, then display -1.

Note: Only one of the three values can be 7.

 

Sample Input and Output



class Tester{
public static void main(String[]args){
int a=2,b=6,c=7;
int x=0;
if(a==7)
{
x=b*c;
}
else if(b==7)
{
x=c;
}
else if(c==7)
{
x=-1;
}
else
{
x=a*b*c;
}
System.out.println(x);
}
}


Methods - Assignment 4

 Methods - Assignment 4


Implement a class Rectangle with the instance variables and methods mentioned below. 

Method Description

calculateArea()

  • Calculate and return the area of the rectangle. The area should be rounded off to two decimal digits.

calculatePerimeter()

  • Calculate and return the perimeter of the rectangle. The perimeter should be rounded off to two decimal digits.

Test the functionalities using the provided Tester class. 

 

Sample Input and Output


class Rectangle{
public float length;
public float width;
public double calculateArea()
{
double a=length*width;
double area=Math.round(a*100.0)/100.0;
return area;
}
public double calculatePerimeter()
{
double p=2*(length+width);
double perimeter=Math.round(p*100.0)/100.0;
return perimeter;
}
}
class Tester{
public static void main(String args[]){
Rectangle rectangle=new Rectangle();
//AssignvaluestothemembervariablesofRectangleclass
rectangle.length=12f;
rectangle.width=5f;
//InvokethemethodsoftheRectangleclasstocalculatetheareaandperimeter
double x=rectangle.calculateArea();
double y=rectangle.calculatePerimeter();
//Displaytheareaandperimeterusingthelinesgivenbelow
System.out.println("Areaoftherectangleis"+x);
System.out.println("Perimeteroftherectangleis"+y);
}
}













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