Results 1 to 6 of 6

Thread: Help please

  1. #1
    baap30 is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Exclamation Help please

    Hi all

    Still learning java and am working on a inventory project this is the first of six seperate parts this first part i recieved a 0 for me to go forward and understand the rest of the parts of this project i need help fixing this first part any all help is greatly apreciated. this is what i have so far.

    // code
    public abstract class inventory3 {



    public void main (String arg[]){
    }{

    ActionProduct ap1 = new ActionProduct("Green AP", 1, 5, 4.99);
    ActionProduct ap2 = new ActionProduct("Red AP", 2, 10, 6.83);

    Product p[] = {ap1, ap2};

    for(int i = 0; i < p.length; ++i) {
    System.out.printf("Product Name: %s, Product Number: %d, Units in Stock: %d, Item Price: $%.2f\n",
    p[i].name, p[i].number, p[i].amount, p[i].price);
    System.out.printf("Inventory Value: $%.2f\n",
    p[i].InventoryValue());
    }
    }
    }

    public class ActionProduct extends Product{


    public class product {

    }

    public void ActionProduct1(String a, int b, int c, double d){
    String name = new String(a);
    int number = b;
    int amount = c;
    double price = d;


    }

    public ActionProduct(String a, int b, int c, double d) {
    // TODO Auto-generated constructor stub
    }

    public double InventoryValue(){
    int price = 0;
    int amount = 0;
    return (amount*price);
    }
    }
    abstract class Product {
    String name;
    int number;
    int amount;
    double price;

    private Product ap2;
    private Product ap1;

    public abstract double InventoryValue();
    Product p[] = {ap1, ap2};

    public Product(String name, int number, int amount, double price, Product ap2, Product ap1) {
    this.name = name;
    this.number = number;
    this.amount = amount;
    this.price = price;
    this.ap2 = ap2;
    this.ap1 = ap1;
    }

    public Product() {
    }


    public int getAmount() {
    return amount;

    }}

    i have classes called Product and ActionProduct

    Like i said i am real new to this and understand the concepts of arrays...writing it in code is a lot harder for me

    the error i am getting is in the actionproduct ..littleyellow triangles stating that the variable name is not read

    i really need to save my grade by understanding this one first

    Thanks in Advance:)

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Put your code in code tags please. It is much unclear :(

  3. #3
    ujjal.ruet is offline Member
    Join Date
    Apr 2010
    Posts
    9
    Rep Power
    0

    Default

    "public void main (String arg[]){
    }{"

    1.There is no main method.

    public class ActionProduct extends Product{
    2.ActionProduct can not be a public class.

    3.public class product {

    }

    //where is the definition of product

  4. #4
    baap30 is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    this assignment is dealing with arrays

    i thought the "public void main (String arg []) was the method

    the product is the ap1 and ap2

    srry i am still learning and am trying to do ths online with no visual aid other then the examples

  5. #5
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Java Code:
    // filename Inventory.java
    // code
    // public abstract class inventory3 { // bad class name, and why abstract? maybe we will find out later
    public abstract class Inventory {
    
            // public void main (String arg[]){ // I think this is just a mistake based on confusion
            // }{
            public static void main(String[] args) { // this is what you want
                    ActionProduct ap1 = new ActionProduct("Green AP", 1, 5, 4.99);
                    ActionProduct ap2 = new ActionProduct("Red AP", 2, 10, 6.83);
    
                    Product p[] = {ap1, ap2};
    
                    for(int i = 0; i < p.length; ++i) {
                            System.out.printf("Product Name: %s, Product Number: %d, Units in Stock: %d, Item Price: $%.2f\n",
                                    p[i].name, p[i].number, p[i].amount, p[i].price);
                            System.out.printf("Inventory Value: $%.2f\n",
                                    p[i].InventoryValue());
                    }
            }
    }
    // we didn't find out why this class was abstract, so it probably shouldn't be
    Java Code:
    // filename ActionProduct.java
    public class ActionProduct extends Product{
    
    // no -- not another public class in the same file!
    // Also, "product" is not the same as "Product" and why have an empty class anyway?
    //public class product {
    //
    //}
            // this is a do-nothing void method that looks like it probably wants
            // to be a constructor. I guess you meant
            //    public ActionProduct(String a, int b, int c, double d) {
            // and even if you did, those parameter names are horribly meaningless
            public void ActionProduct1(String a, int b, int c, double d){                                                                        
                    String name = new String(a); // huh? a is already a String, so what's this about?
                    int number = b;
                    int amount = c;
                    double price = d;
                    // so now we've assigned our parameters to new variables, and
                    // we're going to end the method without doing anything useful.
                    // Since you are extending the abstract Product class, you probably 
                    // want to call that class's constructor here.
            }
    
            public ActionProduct(String a, int b, int c, double d) {
                    // TODO Auto-generated constructor stub
                    // here's the real constructor, but you haven't written it yet
                    // (and it still has the meaningless parameter names)
            }
    
            public double InventoryValue(){
                    int price = 0;
                    int amount = 0;
                    return (amount*price);
                    // this method is useless on several levels. it's a complicated way
                    // to return an int 0 in a method that is supposed to return
                    // a double
            }
    }
    Java Code:
    // filename Product.java
    abstract class Product {
            String name;
            int number;
            int amount;
            double price;
    
            // very weird to have two instance variables of the very class we
            // are trying to define, and there is no clue why these are here
            private Product ap2;
            private Product ap1;
    
            public abstract double InventoryValue();
            Product p[] = {ap1, ap2};
            // another instance variable after an abstract method declaration -- not illegal,
            // but clumsy style
            // also strange to have a Product[] instance variable in the Product class
            // I suspect this is just more confusion
    
            public Product(String name, int number, int amount, double price, Product ap2, Product ap1) {
                    this.name = name;
                    this.number = number;
                    this.amount = amount;
                    this.price = price;
                    this.ap2 = ap2;
                    this.ap1 = ap1;
            }
    
            // empty constructor?
            public Product() {
            }
    
    
            public int getAmount() {
                    return amount;
            }
    }
    All in all, it seems that you are very very confused. You should try to get some alone time with your instructor or TA.

    -Gary-

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

    Default

    -gary-


    Conflicting schedules and time zones prevent me from really spending any one on one time i have some time tonight to work on this and see where i get thanks for the comments and i will be posting if any thing pops up

Posting Permissions

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