Question 1
Program
import java.util.Scanner; //importing Scanner class
public class Main
{
static Scanner sc=new Scanner(System.in); //creating Scanner
Object
static double getLength(){ //getLength method
System.out.print("Enter the length:");
double length=sc.nextDouble();
return length;
}
static double getWidth(){ //getWidth method
System.out.print("Enter the Width:");
double width=sc.nextDouble();
return width;
}
static double getArea(double length,double width){ //getArea
method
double area=length*width;
return area;
}
static void displayData(double length,double width,double area){
//displayData method
System.out.println("Length of the rectangle:"+length);
System.out.println("Width of the rectangle:"+width);
System.out.println("Area of the rectangle:"+area);
}
public static void main(String[] args) {
//calling the methods
double l=getLength();
double w=getWidth();
double area=getArea(l,w);
displayData(l,w,area);
}
}
Screenshot of the program

Output

Question 2
Program
import java.util.Scanner; //importing Scanner class
public class Main
{
static Scanner sc=new Scanner(System.in); //creating Scanner
Object
static void evenOddCounter(int num){ //evenOddCounter method
if(num%2==0)
System.out.println(num+" is even");
else
System.out.println(num+" is odd");
}
public static void main(String[] args) {
int num;
String ch;
do{
System.out.print("Enter the number:");
num=sc.nextInt();
evenOddCounter(num);
System.out.print("Do you want to play again (Y/N)? ");
ch=sc.next();
}while(ch.equals("Y"));
}
}
Screenshot of the program

Output

If you find these answers useful , please rate positive, thankyou
Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...
share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00 pm submit : back to classroom run Instructions from your teacher: #include <iostream> Complete this program. using namespace std; When the program is complete it should ask the user to enter a rectangle's length and width, then display the rectangle's area. The program calls the following functions which need to be completed: double getLength() { // Add code here } double getWidth() { //...
Using basic c++ write a separate code for each of the following: 1. Area Rectangle • Write a program that asks the user to enter length and width of a rectangle and then display the rectangles area. • Write the following functions • getLength – prompt the user to enter length and return that value as a double • getWidth – prompt the user to enter width and return that value as a double • getArea – This method should...
In the code (C++) below, if you input 2 as length and 4 as width, the output is: Enter the rectangle's length: 2 Enter the rectangle's width: 4 Length: 2 | Width: 4 | Area: 8 | Perimeter:12 We worked on this code during class, but there were some things that I did not understand. 1) how does compiler read"l" as length, "w" as width, etc.? I thought you had to update it first, like "w=width." 2) i thought you...
Write a program to display the area of a rectangle after accepting its length and width from the user by means of the following functions: getLength – ask user to enter the length and return it as double getWidth – ask user to enter the width and return it as double getArea – pass width and length, compute area and return area displayArea – pass area and display it in this function. Expected Output: (i) Enter the length: 29 Enter...
Use DevC++ to implement a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(), and getArea() member function should get the...
Use C++ to implement a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(), and getArea() member function should get the...
I need help with the C++ for the following problem: Write a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(),...
Java only please Write a program that displays the following menu: Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Triangle 3. Calculate the Area of a Rectangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the formula: area = ∏r2 Use 3.14159 for ∏. If the user enters 2 the program should ask for...
My assignment is to create a rectangle class in java. •Create a MyRectangleClass •There are two private instance variables, length l and width w with double data type. •There is a constructor with two parameter •There are 4 public methods which are circumference, area, getWidth, and getLength. •circumference method will return circumference to the caller.(the formula for circumference is 2 *l + 2*w ) •Area method Return the area to the caller(:l*w) •getLength method will return length to the caller....
Question 4 Write a program that display the area of a triangle. The program calls the following two functions: .getBaseHeight - This function uses a reference parameter variables to accept a double arguments base and height. This function should ask the user to enter the triangle's buse and height. Input validation: base and height should be positive numbers. calArea - This function should accept the triangle's base and height as arguments and return the triangle's area. The area is calculated...