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() { //...
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...
Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration and definition appRectangle,cpp separate in two different files the class definition and implementation Code: rectangle.h // Rectangle class declaration. class Rectangle { private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; }; //************************************************** // setWidth assigns a value to the width member. * //************************************************** void...
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...
****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...