import java.util.Scanner; public class NewClass16 { privateint length; private i
ID: 3618679 • Letter: I
Question
import java.util.Scanner;
public class NewClass16 {
privateint length;
private int width;
publicvoid intKeyboard()
{
Scanner keyboard = newScanner(System.in);
NewClass16 box = new NewClass16();
System.out.println("Enter the length of it: ");
int l =keyboard.nextInt();
System.out.println("Enter the width of it: ");
int w =keyboard.nextInt();
box.setLength(l);
box.setWidth(w);
}
publicvoid setLength(int len)
{
length = len;
}
publicvoid setWidth(int w)
{
width = w;
}
publicint getLength()
{
return length;
}
publicint getWidth()
{
return width;
}
publicint getArea()
{
return length *width;
}
public static void main(String[] args)
{
NewClass16 box = newNewClass16();
box.intKeyboard();
System.out.println("Thearea of it is " + box.getArea());
}
}
Explanation / Answer
//Hi, i just remove the instance of the class onintKeyboard() function //Try to run it import java.util.Scanner; public class NewClass16 { private int length; private int width; public void intKeyboard() { Scanner keyboard = newScanner(System.in); System.out.println("Enter the length of it: "); int l =keyboard.nextInt(); System.out.println("Enter the width of it: "); int w =keyboard.nextInt(); setLength(l); setWidth(w); } public void setLength(int len) { length = len; } public void setWidth(int w) { width = w; } public int getLength() { return length; } public int getWidth() { return width; } public int getArea() { return length *width; } public static void main(String[] args) { NewClass16 box = newNewClass16(); box.intKeyboard(); System.out.println("Thearea of it is " + box.getArea()); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.