Below is what I have to do and the code is what I have done...I am having trouble with the parts in red... Can someone help me and tell me how to fix it..or show me how to fix it.Thank You!
C. Write a program, which consists of following three classes and one interface.
• Class Fruit with following members:
o protected String color;
o protected double weight;
o public abstract String getColor();
o public abstract double getWeight();
• Interface Edible has only one abstract method getTaste().
• An Apple class inherits Fruit and implements Edible.
• A test class called TestApple will create an instance of Apple and call all above abstract methods and print out an apple object’s color, weight, and taste.
import javax.swing.*; import java.awt.*; public class Fruit { private String color; private double weight; Fruit(){} Fruit(String color, double weight) { this.color=color; this.weight=weight; } public String getcolor() { return color; } public double getweight() { return weight; } public interface Edible { public abstract void getTaste(); } class Apple extends Fruit { public String getTaste() { return null; } public class TestApple { public void main(String[] args) { Apple Apple1 = newApple(); [COLOR="Red"] Apple1.getColor(); Apple1.getWeight(); Apple1.getTaste(); System.out.println(); System.out.println ("Apple Color is: " + Fruit.getColor() ); System.out.println ("Apple Weight is: " + Fruit.getWeight() ); System.out.println ("Apple Taste is: " + Fruit.getTaste() + ".");[/COLOR] } } } }


LinkBack URL
About LinkBacks
Below is what I have to do and the code is what I have done...I am having trouble with the parts in red... Can someone help me and tell me how to fix it..or show me how to fix it.Thank You!
Reply With Quote