Results 1 to 19 of 19
  1. #1
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default I am new to java and new to this class.

    I am new to java. I am taking a course in which I am completely lost in. I was wondering if anyone could help me with the code I have created. I keep coming up with errors and I don't understand well enough to know what I am doing wrong. This is an actionproduct program. That is all the instructor explained. His instructions are below:

    Create a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit). Pay attention to the good programming practices in the text to ensure your source code is readable and well documented


    I will post my program that I have created. This program will not compile properly.

    class ActionProduct extends Product {

    public ActionProduct(String a, int b){
    n = new String(a);
    i = b;
    }

    public static void main (String arg[]){

    ActionProduct = new int []

    ActionProduct item1 = new ActionProduct("salad 1", 1, 3.00);
    ActionProduct item2 = new ActionProduct("salad dressing 2", 1, 1.50);
    ActionProduct item3 = new ActionProduct("bacon bits 3", 2, 1.75);
    ActionProduct item4 = new ActionProduct("croutons 4", 2, 1.75);
    ActionProduct actionprodArray[] = {item1, item2, item3, item4 };

    doubleTotal = 0;
    for(int i = 0; i < actionproductArray.length; ++i); {
    double total = total + (pArray[i].price*pArray[i].stock);







    System.out.println(.........................);//Blank Line
    System.out.printf("ActionProductID%s \tInStock: %d\n\Unit Price: $%.2f\tTotal Inventory:m$%.2f\n\n",

    pArray[i].stock, pArray[i].price, pArray[i].price*pArray[i].stock);
    }End Loop
    }End Main
    }
    public String myaction(){
    return "Action Product";
    }
    }

    //ActionProduct: Inventory Program Part 1

    //ActionProduct Class Defined

    int itemnumb, stock;
    double price;
    String ProdName;
    {
    ProdName = New String (name);
    itemnum = Name;
    stock = Instock;
    Price = ItemPrice;
    }
    }\\End Constructor for ActionProduct Class


    Any help at this point is greatly appreciated.

    Thanks

    Ambria

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default

    I keep coming up with errors
    Please copy and paste the full text of the error messages here.
    Please use code tags when posting code to preserver formatting.

  3. #3
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    It comes up with 25 different errors.

    C:\Users\Desktop>javac actionproduct.java
    actionproduct.java:12: array dimension missing
    ActionProduct item1 = new ActionProduct("salad 1", 1, 3.00);
    ^
    actionproduct.java:28: illegal start of expression
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:28: ';' expected
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:28: illegal start of expression
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:28: ';' expected
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:28: illegal start of expression
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:28: ';' expected
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:28: illegal start of expression
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:28: ';' expected
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:28: illegal start of expression
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:28: ';' expected
    System.out.println(.........................);//Blank Line
    ^
    actionproduct.java:29: illegal escape character
    System.out.printf("ActionProductID%s \tInStock: %d\n\Unit Price: $%.2f\t
    Total Inventory:m$%.2f\n\n",
    ^
    actionproduct.java:32: ';' expected
    }End Loop
    ^
    actionproduct.java:33: ';' expected
    }End Main
    ^
    actionproduct.java:35: class, interface, or enum expected
    public String myaction(){
    ^
    actionproduct.java:37: class, interface, or enum expected
    }
    ^
    actionproduct.java:45: class, interface, or enum expected
    double price;
    ^
    actionproduct.java:46: class, interface, or enum expected
    String ProdName;
    ^
    actionproduct.java:47: class, interface, or enum expected
    {
    ^
    actionproduct.java:49: class, interface, or enum expected
    itemnum = Name;
    ^
    actionproduct.java:50: class, interface, or enum expected
    stock = Instock;
    ^
    actionproduct.java:51: class, interface, or enum expected
    Price = ItemPrice;
    ^
    actionproduct.java:52: class, interface, or enum expected
    }
    ^
    actionproduct.java:53: illegal character: \92
    }\\End Constructor for ActionProduct Class
    ^
    actionproduct.java:53: illegal character: \92
    }\\End Constructor for ActionProduct Class
    ^
    25 errors

    C:\Users\Desktop>

    I copied and pasted what comes up on my command prompt. I am not sure what a tag is as I am new to this forum.

  4. #4
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    This line is a problem
    Java Code:
    System.out.println(.........................);//Blank Line
    You either need to wrap it in quotes
    Java Code:
    System.out.println(".........................");//Blank Line
    or just add a new line
    Java Code:
    System.out.println("\n");//Blank Line
    I don't know if this was causing all of the errors, but it was causing some of them.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default

    ActionProduct = new int []
    What is this statement supposed to do?
    This looks like an assignment statement: variable on the left of =, expression on the right.
    However ActionProduct is the name of the class, not the name of a variable.

    System.out.println(.........................);//Blank Line
    What are the ..... here? A blank line could be created by println(""); // an empty String

    actionproduct.java:29: illegal escape character
    System.out.printf("ActionProductID%s \tInStock: %d\n\Unit Price: $%.2f\t
    Look at all the \x sequences where x is t or n or ?? The \ character is called an escape character and tells the compiler that the char following it is special and should be treated in a special way. For example "\n" say that the n is not "n" but should be a newline character. One of the letters that follows \ in the above is an "illegal escape character".

  6. #6
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    The t and the n is what the instructor already had in the program that he started. I just added to that. I will fix the other errors right now. Now how would I modilfy what I have here to hande multiple items with an array? It has to display one product at a time. I also have to create a method to calculate my whole inventory. I am not sure on how to start that part. I think I am over my head in this class but I cannot and will not drop it. I am determined to understand.

    Ambria

  7. #7
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default Repost with code tags?

    Can you repost the code with code tags? Simply put
    XML Code:
    [CODE] and [/CODE]
    around it.

    Example:
    XML Code:
    [CODE]System.out.println("hello world");[/CODE]
    will look like:
    Java Code:
    System.out.println("hello world");

  8. #8
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    Is there something I click on to add the codes or do I just type them in and it will look like what you posted?

    Sorry for being so confused :(

    Ambria

  9. #9
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    Quote Originally Posted by ambria1975 View Post
    Is there something I click on to add the codes or do I just type them in and it will look like what you posted?
    You can either type them, or click the # when you're writing a post.

  10. #10
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    class ActionProduct extends Product {

    public ActionProduct(String a, int b){
    n = new String(a);
    i = b;
    }
    public static void main (String arg[]){

    [code]ActionProduct item1 = new ActionProduct("salad 1", 1, 3.00);
    [code]ActionProduct item2 = new ActionProduct("salad dressing 2", 1, 1.50);
    [code]ActionProduct item3 = new ActionProduct("bacon bits 3", 2, 1.75);
    [code]ActionProduct item4 = new ActionProduct("croutons 4", 2, 1.75);
    [code]ActionProduct actionprodArray[] = {item1, item2, item3, item4 };
    [code]doubleTotal = 0;
    [code]for(int i = 0; i < actionproductArray.length; ++i); {
    [code]double total = total + (pArray[i].price*pArray[i].stock);




    [code]System.out.println("");//Blank Line
    Java Code:
    System.out.printf("ActionProductID%s \tInStock: %d\n\Unit Price: $%.2f\tTotal Inventory:m$%.2f\n\n"; 
    [code]pArray[i].stock, pArray[i].price, pArray[i].price*pArray[i].stock);
    } //End Loop
    } //End Main [/code]
    }
    [code]public String myaction(){
    Java Code:
    return "Action Product";
    }
    }
    //ActionProduct: Inventory Program Part 1 (this is suppose to be a class file. Wasn't sure if it should be separate or with the rest of the program)
    //ActionProduct Class Defined
    [code]int itemnumb, stock;
    [code]double price;
    [code]String ProdName;
    {
    [code]ProdName = New String (name);
    [code]itemnum = Name;
    [code]stock = Instock;
    Java Code:
    Price = ItemPrice;
    }
    }\\End Constructor for ActionProduct Class

  11. #11
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    By looking at this I think that I might have messed it up more. I will try again! It would not let me preview it for some reason. Sorry about that!

  12. #12
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    Java Code:
    class ActionProduct extends Product {
     
      public ActionProduct(String a, int b){
      n = new String(a);
      i = b;
     }
    public static void main (String arg[]){
     
       ActionProduct item1 = new ActionProduct("salad 1", 1, 3.00);
       ActionProduct item2 = new ActionProduct("salad dressing 2", 1, 1.50);
       ActionProduct item3 = new ActionProduct("bacon bits 3", 2, 1.75);
       ActionProduct item4 = new ActionProduct("croutons 4", 2, 1.75);
       ActionProduct actionprodArray[] = {item1, item2, item3, item4 };
        doubleTotal = 0;
        for(int i = 0; i < actionproductArray.length; ++i); {
         double total = total + (pArray[i].price*pArray[i].stock);
     
     
     
     
     System.out.println("");//Blank Line
        System.out.printf("ActionProductID%s \tInStock: %d\n\Unit Price: $%.2f\tTotal Inventory:m$%.2f\n\n"; 
         pArray[i].stock, pArray[i].price, pArray[i].price*pArray[i].stock);
       } End Loop
     } End Main
    }
     public String myaction(){
       return "Action Product";
     }
    }
    //ActionProduct: Inventory Program Part 1
    //ActionProduct Class Defined
     
     int itemnumb, stock;
     double price;
     String ProdName;
         {
     ProdName = New String (name);
     itemnum = Name;
     stock = Instock;
     Price = ItemPrice;
         }
    }\\End Constructor for ActionProduct Class

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

    Default

    I see lots of mistakes there including typos and such. I think that you should change your approach to coding by only adding a little bit of code at any one time, compiling immediately after adding this code, and then not adding any more code until you fix the errors that are present. If you do it this way, you'll prevent your code from accumulating so many errors that it becomes unfix-able.

    One big error, by the way, the typo: doubletotal, which should likely be double total; You should not declare total from within the for loop but rather before the loop (likely at the spot of this typo above).

  14. #14
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    I changed the doubletotal to double total like you said. I started with 19 errors and now I have 27. I started this program with a template the instrctor gave me. I was doing good the first half of the class and now I am just plain lost. Any help is greatly appreciated. When you mention typos, I have no idea what you are referring too. Can you elaborate further on that? Thanks for all help!!

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default

    typos refers to a mistype. Like spelling double as doble or forgetting the blank: intvar vs int var;
    You'll need to post the errors for anyone to help. No crystal balls here.

    I started this program with a template
    I suspect this must have been pseudo code, not an actual program that would compile.
    If the program would compile, perhaps you should take Fubarable 's advice and make your changes in small steps, compile it and correct the errors. 27 errors can be overwhelming.

  16. #16
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    Yes, it is extremely overwhelming. I have to fix this portion to get to the next step that was due two days ago. Then tomorrow I have a third step that is due and at this point I want to give up but that is not my character. I am doing my best to understand with the little amount of resources that are available to me. I will start over and keep my fingers crossed.

    I do have a question. If my class path is not set correctly using java, would that create some of these errors?

  17. #17
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Java Code:
    class ActionProduct extends Product {
    
    public ActionProduct(String a, int b){
    n = new String(a);
    i = b;
    }
    where are n and i declared?

    variable names leave alot to be desired aswell, get into good habits early, single letter non descriptive variable names will just cause you pain later.

  18. #18
    ambria1975 is offline Member
    Join Date
    Jun 2010
    Posts
    11
    Rep Power
    0

    Default

    That portion is part of the template that was put in by the instructor. I do not see why I cannot change it and if I were to change it, do you have any suggestions?

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default

    If my class path is not set correctly using java, would that create some of these errors
    No. Your errors are mostly created by what you typed in. An error with classpath would cause the compiler not to be able to find some class. That usually doesn't happen with your first few programs. Later as your programs get more complex, it will be a concern.

    Variable names should reflect their content or usage.
    It looks like 'n' being a String should be changed to 'nameOfProduct'.
    And 'i' being an int should probably be 'count' or 'numberOf' or ???
    Last edited by Norm; 06-27-2010 at 03:28 AM.

Similar Threads

  1. Replies: 1
    Last Post: 05-31-2009, 10:57 PM
  2. Replies: 1
    Last Post: 05-31-2009, 02:17 PM
  3. Replies: 16
    Last Post: 05-28-2009, 03:41 PM
  4. Replies: 14
    Last Post: 05-28-2009, 05:44 AM
  5. class.java to class.exe
    By f_the_cook in forum New To Java
    Replies: 11
    Last Post: 07-16-2008, 02:24 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
  •