Can someone please help with this in JAVA?
Write one application program by using the following requirements:
1) Exception handling
2) Inheritance
a) At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods
b) At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods
c) At least one interface: this interface needs to have at least two abstract methods
d) At least one method overloading
e) At least one method overriding
f) At least one static member and one static method
g) Polymorphism: you need to have at least one superclass reference to reference objects of a subclass
3. Within your application, please include comments at the places where you use the above items.
**This is what I have so far***
public class gatorade {
public void nutrition() {
System.out.println("nutrition facts method");
System.out.println("90 Calories");
System.out.println("0 Grams Fat");
System.out.println("20 MG Sodium");
System.out.println("18 Grams Sugar");
System.out.println("0 Grams Protein");
}
}
//inheritance
public class blueberry extends gatorade{
System.out.println("Color is blue");
public class orange extends gatorade{
System.out.println("Color is orange");
public class lemonlime extends gatorade{
System.out.println("Color is yellow");
public class fruitpunch extends gatorade{
System.out.println("Color is red");
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Shape.java
public interface Shape {
void displayShape();
double calArea();
}
________________________
// ShapeAbstract.java
public abstract class ShapeAbstract implements Shape {
String shape;
public ShapeAbstract(String shape) {
super();
this.shape = shape;
}
@Override
public void displayShape() {
System.out.println("Shape :" +
shape);
}
@Override
public String toString() {
return "shape=" + shape;
}
}
______________________________
// Circle.java
public class Circle extends ShapeAbstract {
private double radius;
public Circle(double radius) {
super("Circle");
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
@Override
public double calArea() {
return Math.PI * radius *
radius;
}
}
__________________________
// Rectangle.java
public class Rectangle extends ShapeAbstract {
private double length;
private double width;
public Rectangle(double length, double width)
{
super("Rectangle");
this.length = length;
this.width = width;
}
@Override
public double calArea() {
return length * width;
}
@Override
public String toString() {
return super.toString() + "
length=" + length + ", width=" + width
+ " Area =" + calArea();
}
}
_________________________
// Circle.java
public class Circle extends ShapeAbstract {
private double radius;
public Circle(double radius) {
super("Circle");
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
@Override
public double calArea() {
return Math.PI * radius *
radius;
}
@Override
public String toString() {
return super.toString() + "
Radius=" + radius+ " Area =" + calArea();
}
}
_________________________
// Test.java
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
double length,width,radius;
ArrayList<ShapeAbstract> sa=new
ArrayList<ShapeAbstract>();
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
while(true)
{
try
{
System.out.print("Enter the
length :");
length=sc.nextDouble();
if(length<0)
{
throw new
InvalidInputException("** Must be greater than 0 **");
}
else
break;
}
catch(Exception e)
{
continue;
}
}
while(true)
{
try
{
System.out.print("Enter the
width :");
width=sc.nextDouble();
if(width<0)
{
throw new
InvalidInputException("** Must be greater than 0 **");
}
else
break;
}
catch(Exception e)
{
continue;
}
}
sa.add(new
Rectangle(length, width));
while(true)
{
try
{
System.out.print("Enter the
radius :");
radius=sc.nextDouble();
if(radius<0)
{
throw new
InvalidInputException("** Must be greater than 0 **");
}
else
break;
}
catch(Exception e)
{
continue;
}
}
sa.add(new Circle(radius));
for(int
i=0;i<sa.size();i++)
{
System.out.println(sa.get(i));
}
}
}
_________________________
Output:
Enter the length :5
Enter the width :6
Enter the radius :5.5
shape=Rectangle length=5.0, width=6.0 Area =30.0
shape=Circle Radius=5.5 Area
=95.03317777109123
___________________Thank You
Can someone please help with this in JAVA? Write one application program by using the following...
Write ONE application program by using the following requirements: Using JAVA File input and output Exception handling Inheritance At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods At least one interface: this interface needs to have at least two abstract methods At least one method overloading At least one method overriding At least...
In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class. The class should extend the Dog class. 2. Look at the following code, which is the first line of a class definition: public class Tiger extends Felis In what order will the class constructors execute? 3. Write the statement that calls a superclass constructor and passes the arguments x, y, and z. 4. A superclass has the following method: public void setValue(int v) value...
In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...
Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you Create a superclass called VacationInstance Variables destination - String budget - double Constructors - default and parameterized to set all instance variables Access and mutator methods budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in...
PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1. What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** * Program: PRG/421 Week 1 Analyze Assignment * Purpose: Analyze the coding for...
What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s ■ Demon "Declare a variable of the superclass type and assign it an instance of the subclass type strate polymorphic behavior Access the public members of the superclass type Notice how the overridden versions of the subclass type are called Notice how the subclass specific members are inaccessible "Create an array of superclass type and use a foreach loop to...
In JAVA, please In this module, you will combine your knowledge of class objects, inheritance and linked lists. You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: 1. description - which is a string 2. write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money...
PLEASE HELP this is the last part of my lab and I need help ): add comments please (: if it is too difficult you do not have to do part 3 but it would be greatly appreciated if you do ! Obtain example code files Circle.java, Shape.java, CircleShape2.java, Sphere.java, and CircleShapeApp.java from the downloaded files in Ch8. Compile and execute the example and understand the polymorphism it performs. (I have copied and pasted all of these files below) Modify...
(1) ____ is the principle that allows you to apply your knowledge of a general category to more specific objects. a. Inheritance c. Encapsulation b. Polymorphism d. Override (2) When you create a class by making it inherit from another class, you are provided with data fields and ____ automatically. a. fonts c. class names b. methods d. arrays (3) By convention, a class diagram contains the ____ following each attribute or...
Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume of rectangular objects. First, write an abstract super class RectangularShape, then write a subclass Rectangle that inherits from the super class to compute areas of rectangles, including squares if there is only one data. Finally, write another subclass Cuboid that inherits from its super class Rectangle above to compute surface areas and volumes of cuboids, including 3 equal sided cube. Must apply code-reusability in...