Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Driver: /* * To change this license header, choose License Headers in Project Pr

ID: 3707720 • Letter: D

Question

Driver:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author kerlin
*/
public class Driver
{

    /**
     * Main method to run our code
     * @param args NOT USED
     */
    public static void main(String[] args)
    {
        Orange myFruit = new Orange(14, 4);
        System.out.println("Printing My fruit: " + myFruit);
        System.out.println("Juicing My fruit: " + myFruit.juice());
        Fruit yourFruit = new Fruit(20);
        System.out.println("Printing Your fruit: " +yourFruit);
        yourFruit.setSeeds(5);
        System.out.println("Your fruit should now have 5 seeds: " + yourFruit.getSeeds());
        myFruit.setDiameter(10);
        System.out.println("My fruit should now be 10 units in diameter: " + myFruit.getDiameter());
        System.out.println("My fruit should now juice 5 units: " + myFruit.juice());

    }
}

Problem 2: Foods or n s pro Dem, you Will De creating a derived Class, Dase class and an?n emace . NO Drivers equ?re with. A UML diagram for this problem has been provided to assist you Fruit Class: Attribute: o Number of Seeds per instance Methods: o get and set methods for attribute o toString): returns a String describing the Fruit o constructor that takes in the Fruit's seed count Juiceable Interface: Juiceable should be its own interface which has a: Method header: juice(): returns the amount of juice obtained if the object was juiced Orange Object: Orange should be its own class and should inherit from Fruit and implement Juiceable. Orange should have: Attributes: diameter of Orange Methods: o get and set methods for diameter of Orange o toString): returns a String describing the Orange o constructor which takes in the Orange's seed count o constructor which takes in the Orange's seed count and the Orange's diameter ojuice() returns 2 units of juice for every 4 units of diameter Grading Breakdown: 10- -Correctly creating your Interface 10 -Correctly creating your Base Object 10--Correctly creating your Derived Object 10--Correctly connecting your data using the correct keywords, etc

Explanation / Answer

Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

Fruit.java
==========

public class Fruit {
private int seeds;

public Fruit(int seeds)
{
this.seeds = seeds;
}

public int getSeeds() {
return seeds;
}

public void setSeeds(int seeds) {
this.seeds = seeds;
}


public String toString()
{
return "Fruit with " + seeds + " seeds";
}
}


Juiceable.java
-============


public interface Juiceable {
public int juice();
}

Orange.java
============

public class Orange extends Fruit implements Juiceable {
private int diameter;

public Orange(int seeds) {
super(seeds);
diameter = 4; //default diameter
}


public Orange(int seeds, int dia) {
super(seeds);
diameter = dia;
}


public int getDiameter() {
return diameter;
}


public void setDiameter(int diameter) {
this.diameter = diameter;
}


@Override
public int juice() {
return (int) Math.ceil(diameter / 4.0 * 2); //2 units of juice for every 4 units of diameter
}

public String toString()
{
return "Orange " + super.toString();
}
}

outupt of Driver.java
=====
Printing My fruit: Orange Fruit with 14 seeds
Juicing My fruit: 2
Printing Your fruit: Fruit with 20 seeds
Your fruit should now have 5 seeds: 5
My fruit should now be 10 units in diameter: 10
My fruit should now juice 5 units: 5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote