Q:

Write a Java program that define class Rectangle with two instance variables length and width of integer type. Define set and get methods for writing and reading values of length and width variables. Define main method to test class Rectangle

0

Write a Java program that define class Rectangle with two instance variables length and width of integer type. Define set and get methods for writing and reading values of length and width variables. Define main method to test class Rectangle.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

package rectangle;

import java.util.Scanner;

public class Rectangle {

    private int length;
     private int width;
     public void setlength(int length)
     {
       this.length = length;
     }
     public int getlength()
     {
        return length;
     }
     public void setwidth(int width)
     {
     this.width = width;
     } 
     public int getwidth()
     {
        return width;
     } 
    public static void main(String[] args) {
        Scanner rr = new Scanner(System.in);
        Rectangle r1 = new Rectangle();
        
        int L;
        L = rr.nextInt();
        int W;
        W = rr.nextInt();
        r1.setlength(L);
        r1.setwidth(W);
        System.out.println("Length= "+ r1.getlength());
        System.out.println("width= "+ r1.getwidth());
        
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now