Question: COMP: (Please use java) For the Fruit java class and the TropicalFruit java class, write a test class called FruitTest and TropicalFruitTest that tests the

COMP: (Please use java) For the Fruit java class and the TropicalFruit java class, write a test class called FruitTest and TropicalFruitTest that tests the method toString() in each. Ensure you test it with three different inputs. Submit only the test java files. Make sure you test all boundary conditions. (Below are the codes for each)

/** * Write a description of class Fruits here. * * @author (your name) * @version (a version number or a date) */ public class Fruit { String fruitName; String color; public Fruit () { fruitName=""; color=""; } public Fruit(String name, String c) { fruitName=name; color=c; } public String toString() { return("The fruit "+fruitName+" is of color "+color); } }

--------------------------------------------------------------------------------------------------------------

 public class TropicalFruit extends Fruit { double price; public TropicalFruit() { super(); price=0; } public TropicalFruit(String name,String c, double p) { super(name,c); price=p; } public String toString() { return (super.toString()+" and it costs "+price+" dollars"); } public static void main(String[] args) { Fruit f=new Fruit("apple","red"); TropicalFruit tf = new TropicalFruit("mango", "yellow", 3.2); Fruit fr = tf; // polymorphism tf = (TropicalFruit)f; // ok to have parent class on the left of assignment and subclass on the right // of assignment. Syntax error the other way around System.out.println(f.toString()); System.out.println(tf.toString()); System.out.println(fr.toString()); // the last print statement can either call Fruit's toString or // TropicalFruit's toString() method. // fr is a Fruit reference //but fr is referencing a TropicalFruit object // is the reference going to be the decider for the method call // or the object????? /// Here the object method will be the one to be called // this is called dynamic binding } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!