Question
Im having one small problem I have my main class & my superclass working but I need the method in my subclass to work. ?MAIN
Im having one small problem I have my main class & my superclass working but I need the method in my subclass to work.
?MAIN CLASS:
public static void main(String[] args) { Circle cir = new Circle(); Oval oval = new Oval(); //Change Cir() to Oval() cir.setRad1(21.5); System.out.println("Circle characteristics"); System.out.printf("Radius: %.2f ", cir.getRad1()); //use getRad1 to call System.out.printf("Area: %.2f ", cir.calculateArea()); //change to oval.calculateArea() cir.setRad2(11.32); System.out.println(" Oval Characteristics"); System.out.printf("Radius 1: %.2f ", cir.getRad1()); //use subclass cir to get the first radius of circle System.out.printf("Radius 2: %.2f ", cir.getRad2()); System.out.printf("Oval Area: %.2f ", oval.calculateArea()); } //End Main Method
SUPERCLASS:
import java.lang.Math;
//Begin Subclass Circle public class Circle extends Midweek_Week11{ private double rad1; private double rad2;
public void setRad1(double r1) { //make public rad1 = r1; } public double getRad1() { return rad1; } public void setRad2(double r2) { //make Public rad2 = r2; } public double getRad2() { //this switched to getRad return rad2; } public double calculateArea() { return Math.PI * Math.pow(rad1, 2); //inset Math. before PI and pow }
SUBCLASS:
public class Oval extends Circle{ @Override public double calculateArea() { return PI * (getRad1 * getRad2); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started