Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Abstract Help

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Abstract Help

    Hello,

    I have this code

    public class BulkFoodQ2 extends FoodV5
    {
    private double unitCost;

    public BulkFoodQ2(String brandIn, String productNameIn, String unitsIn, double unitCostIn)
    {
    super(brandIn, productNameIn, unitsIn);
    unitCost = unitCostIn;
    }

    public void setUnitCost(double unitCostIn)
    {
    unitCost = unitCostIn;
    }

    public double getUnitCost()
    {
    return unitCost;
    }

    public void setUnitCostToThisUnitCost(FoodV5 anotherFood)
    {
    double tempUnitCost = anotherFood.getUnitCost();
    setUnitCost(tempUnitCost);
    }

    public double findCost(double amount)
    {
    return amount * unitCost;
    }

    }

    The class FoodV5 is an abstract, class and I am not understanding how to test the method.

    I am trying to test the setUnitCostToThisUnitCost.

    I created this:

    public class TestBulkFoodQ2
    {
    public static void main(String[] args)
    {

    FoodV5[] food = new FoodV5[2];

    food[0] = new BulkFoodQ2("Grain", "White Man", "Rice", 10.00);
    food[1] = new BulkFoodQ2("Pasta", "Wheatie", "Noodles", 15.00);

    for (FoodV5 f : food)
    System.out.println(f.getBrand() + ", " + f.getProductName() + ", " + f.getUnits() + ", " + f.getUnitCost());

    food.setUnitCostToThisUnitCost(10.00);
    System.out.println(food);

    }

    }

    The first part but the method for setUnitCostToThisUnitCost does not work. Any help would be appreciated


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Abstract Help

    does not work
    Please explain "what does not work" means.
    If there are error messages, copy the full text and paste here.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Abstract method in a non-abstract class
    By bassie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 2nd, 2012, 11:27 AM
  2. abstract
    By anis.laghaei in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 23rd, 2012, 12:26 PM
  3. ABSTRACT
    By anis.laghaei in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 11th, 2012, 07:16 AM
  4. GUI error: is not abstract and does not override abstract method
    By djl1990 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 21st, 2011, 01:26 PM
  5. Abstract
    By mamawia in forum Java Theory & Questions
    Replies: 2
    Last Post: September 3rd, 2011, 07:16 AM