Results 1 to 7 of 7

Thread: Apple Items

  1. #1
    Snatch is offline Member
    Join Date
    Apr 2010
    Posts
    6
    Rep Power
    0

    Exclamation Apple Items

    Below is what I have to complete, and the program is what i have done so far. I am having problems with the red items. Can someone let me know what might be wrong and di I have everything I should! Thank you in advance!

    1.-Need to write the exact same program.
    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.

    Java Code:
    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)
    {
    	[COLOR="red"]Apple Apple1 = newApple();[/COLOR]
    	[COLOR="red"]Apple1.getColor("Red");[/COLOR]
    	[COLOR="red"]Apple1.getWeight(1.2);[/COLOR]
    	Apple1.getTaste();
    
    System.out.println();
    [COLOR="red"]System.out.println ("Apple Color is: " + Fruit.getColor() );[/COLOR]
    [COLOR="red"]System.out.println ("Apple Weight is: " + Fruit.getWeight() );[/COLOR]
    [COLOR="red"]System.out.println ("Apple Taste is: " + Fruit.getTaste() + ".");[/COLOR]
    }
    }
    }
    }
    Moderator Edit: Code tags added
    Last edited by Fubarable; 04-04-2010 at 09:40 PM. Reason: Moderator Edit: Code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I see a problem here:
    Java Code:
    	Apple Apple1 = newApple();
    	Apple1.getColor("Red");
    	Apple1.getWeight(1.2);
    	Apple1.getTaste();
    where you seem to be trying to use a getter method as a setter. Can't be done; won't compile.

    Also, I added code tags to your code (please see the link in my signature below to see how to do this yourself), but while it will make your posted code easier to read, it would be easier still for others to read if it is properly formatted.

    Also, let me welcome you to this forum!

    edit: also, are you following all the directions?

    • Class Fruit with following members:
    o protected String color;

    o protected double weight;

    o public abstract String getColor();

    o public abstract double getWeight();
    Last edited by Fubarable; 04-04-2010 at 09:45 PM.

  3. #3
    Snatch is offline Member
    Join Date
    Apr 2010
    Posts
    6
    Rep Power
    0

    Default

    Thank You!

    How would I fix it to make it work?

    Thank You Again!!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    For one: don't use getters as setters -- it just won't work.
    Next: Follow all directions given to you by your instructor.
    One possible change: give Apple a constructor that allows you to pass parameters.
    Change that method in Apple that returns null
    Keep studying your text and notes. Learning to program isn't easy and requires a lot of effort.

    Much luck!

  5. #5
    Snatch is offline Member
    Join Date
    Apr 2010
    Posts
    6
    Rep Power
    0

    Default

    Ill try Thank You!

  6. #6
    Snatch is offline Member
    Join Date
    Apr 2010
    Posts
    6
    Rep Power
    0

    Default

    I cannot figure this out!!

    Can youn give me a little more help?? I have been working on this on and it is 11 pm here I am station in Germany!
    Last edited by Snatch; 04-04-2010 at 10:32 PM.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Snatch View Post
    I cannot figure this out!!

    Can youn give me a little more help??
    What changes have you made and what errors or problems are now occurring?

    I have been working on this on and it is 11 pm here I am station in Germany!
    Better to post the information relevant to the problem itself (that I've requested above) than this as it doesn't really affect what help we can or should give.

    Best of luck!

Similar Threads

  1. Compiler in Apple system ..!!
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 5
    Last Post: 01-18-2010, 07:46 PM
  2. Forsale: Brand New Apple Iphone 3G 16gb Unlocked @250usd
    By escot in forum Reviews / Advertising
    Replies: 1
    Last Post: 04-17-2009, 05:12 AM
  3. apple plug-in
    By willemjav in forum Java Applets
    Replies: 7
    Last Post: 05-04-2008, 01:07 PM
  4. Java and Apple
    By cubidoo in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2007, 09:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •