Shapes lab for Java course | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Shapes lab for Java course

The code doesn't work. What do I need to change? ------------------ import java.util.Scanner; import java.math.BigDecimal; abstract class Shapes { BigDecimal width; abstract void area(); } //your code goes here class Square extends Shapes{ BigDecimal width; public Square(BigDecimal x) { this.width = x; } public void area(){ System.out.println(this.width.multiply(this.width)); } } class Circle extends Shapes{ BigDecimal width; public Circle(BigDecimal y){ this.width = y; } public void area(){ System.out.println(this.width.multiply(this.width.multiply(new BigDecimal(Math.PI))).doubleValue()); } } public class Program { public static void main(String[ ] args) throws Exception { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); if (x <= 0 && x <= Integer.MAX_VALUE) { throw new Exception(); } else { BigDecimal x_float = new BigDecimal(x); Square a = new Square(x_float); a.area(); } if (y <= 0 && y <= Integer.MAX_VALUE) { throw new Exception(); } else { BigDecimal y_float = new BigDecimal(y); Circle b = new Circle(y_float); b.area(); } if (x <= 0 && y <= 0) { throw new Exception(); } } }

19th Jan 2021, 2:57 PM
Shyamal Chandra
4 Answers
0
Your code is woRkiNg properly but i doing mistakes after running give two input your code calculating correct check again.
19th Jan 2021, 3:04 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Could you please write in English, ♨️♨️?
19th Jan 2021, 3:23 PM
Shyamal Chandra
0
Shyamal Chandra you can copy text and paste on google translator.
19th Jan 2021, 3:27 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } class Square extends Shape{ public int area2; public Square(int x) { width=x; } public void area() { area2=width*width; System.out.println(area2); } } class Circle extends Shape { public double area1; public Circle(int y) { width=y; } public void area() { area1=Math.PI*width*width; System.out.println(area1); } } public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); Square a = new Square(x); Circle b = new Circle(y); a.area(); b.area(); } }
24th Jun 2021, 3:47 PM
Dharmi Sri
Dharmi Sri - avatar