Results 1 to 6 of 6

Thread: Getting errors

  1. #1
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default Getting errors

    Hello,

    I am having a lot of problems with this code.Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Syntax error, insert ")" to complete Expression
    Syntax error, insert ";" to complete Statement
    Syntax error, insert "}" to complete Block

    at Inventory.main(Inventory.java:63)




    public class Inventory{

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    class Product {

    private int itemNumber;
    private String name;
    private int unitsInStock;
    private double unitPrice;

    public Product(int itemNumber, String name, int unitsInStock,
    double unitPrice) {
    this.itemNumber = itemNumber;
    this.name = name;
    this.unitsInStock = unitsInStock;
    this.unitPrice = unitPrice;
    }

    public double getValueOfProduct() {
    return unitsInStock * unitPrice;
    }


    public String toString() {
    String itemStr = "Item: " + String.format("%-3s | ", itemNumber);
    String titleStr = "Name: " + String.format("%-10s | ", name);
    String unitsStr = "Units: " + String.format("%4d | ", unitsInStock);
    String costStr = "Unit: " + String.format("$ %6.2f | ", unitPrice);
    String valueStr = "Value: "
    + String.format("$ %8.2f", getValueOfProduct());

    return itemStr + titleStr + unitsStr + costStr + valueStr;
    }

    }

    {

    {

    Product one = new Product(1, "Polaris90", 2, 1000.00);
    Product two = new Product(2, "Polaris125", 3, 1250.50);
    Product three = new Product(3, "POLARIS250", 1, 2999.00);
    Product four = new Product(4, "YAMAHA90", 2, 1199.99);
    Product five = new Product(5, "Yamaha110", 5, 1299.00);
    Product six = new Product(6, "Suzuki50", 7, 812.50);



    System.out.println(one);
    System.out.println(two);
    System.out.println(three);
    System.out.println(four);
    System.out.println(five);
    System.out.println(six);
    System.out.println(one.getValueOfProduct() + two.getValueOfProduct()
    + three.getValueOfProduct() + four.getValueOfProduct() + five.getValueOfProduct()
    + six.getValueOfProduct()}
    }

    private Productinfo getProductInfoFromUser1()
    String name = getItemName(); // product's name
    if (name == null) { return null; }
    int num = getItemNumber(); // product's item number
    int stock = getStock(); // product's stock quantity
    double price = getPrice();
    return new Productinfo( num, name, stock, price);
    }

    private double getPrice() {
    // TODO Auto-generated method stub
    return 0;
    }
    private int getStock() {
    // TODO Auto-generated method stub
    return 0;
    }
    private int getItemNumber() {
    // TODO Auto-generated method stub
    return 0;
    }
    private String getItemName() {
    // TODO Auto-generated method stub
    return null;
    }

    }
    }





    }

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

    Default

    Sorry, for being blunt, but this code above is a mess. I suggest you take it out back and shoot it. Seriously, start over, but this time, compile frequently, perhaps after every new line of code, and make it a rule to add nothing to the code until the current code compiles well. Else you'll end up with an untenable mess. Oh, and please use code tags as it will make it easier for others to help you here.

    Much luck!

  3. #3
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default Tags

    I know the post is bad and will remove I will have to study up on usage of tags. My instructor doesn't ever seem to have the time.

    Thanks

  4. #4
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    Code tags are only used when asking questions about code on a forum like this one. Type [code] some code here [ /code] to make a code block with out the space between [ and /. This makes it much easier for others to read your code.
    ex.
    Java Code:
    Some code here.

  5. #5
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default Tags

    I think I have the idea of tags and have the first part of the program running.
    tem: 1 | Name: Polaris90 | Units: 2 | Unit: $ 1000.00 | Value: $ 2000.00
    Item: 2 | Name: Polaris125 | Units: 3 | Unit: $ 1250.50 | Value: $ 3751.50
    Item: 3 | Name: POLARIS250 | Units: 1 | Unit: $ 2999.00 | Value: $ 2999.00
    Item: 4 | Name: YAMAHA90 | Units: 2 | Unit: $ 1199.99 | Value: $ 2399.98
    Item: 5 | Name: Yamaha110 | Units: 5 | Unit: $ 1299.00 | Value: $ 6495.00
    Item: 6 | Name: Suzuki50 | Units: 7 | Unit: $ 812.50 | Value: $ 5687.50
    23332.98
    but how woud I use a sort for this and display one unit at a time ?

    Code:
    public class Inventory{

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    class Product {

    private int itemNumber;
    private String name;
    private int unitsInStock;
    private double unitPrice;

    public Product(int itemNumber, String name, int unitsInStock,
    double unitPrice) {
    this.itemNumber = itemNumber;
    this.name = name;
    this.unitsInStock = unitsInStock;
    this.unitPrice = unitPrice;
    }

    public double getValueOfProduct() {
    return unitsInStock * unitPrice;
    }


    public String toString() {
    String itemStr = "Item: " + String.format("%-3s | ", itemNumber);
    String titleStr = "Name: " + String.format("%-10s | ", name);
    String unitsStr = "Units: " + String.format("%4d | ", unitsInStock);
    String costStr = "Unit: " + String.format("$ %6.2f | ", unitPrice);
    String valueStr = "Value: "
    + String.format("$ %8.2f", getValueOfProduct());

    return itemStr + titleStr + unitsStr + costStr + valueStr;
    }

    }

    {

    {

    Product one = new Product(1, "Polaris90", 2, 1000.00);
    Product two = new Product(2, "Polaris125", 3, 1250.50);
    Product three = new Product(3, "POLARIS250", 1, 2999.00);
    Product four = new Product(4, "YAMAHA90", 2, 1199.99);
    Product five = new Product(5, "Yamaha110", 5, 1299.00);
    Product six = new Product(6, "Suzuki50", 7, 812.50);



    System.out.println(one);
    System.out.println(two);
    System.out.println(three);
    System.out.println(four);
    System.out.println(five);
    System.out.println(six);
    System.out.println(one.getValueOfProduct() + two.getValueOfProduct()
    + three.getValueOfProduct() + four.getValueOfProduct() + five.getValueOfProduct()
    + six.getValueOfProduct());
    }
    }

    }
    }

  6. #6
    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 Abbinormal View Post
    I think I have the idea of tags and have the first part of the program running.
    No you don't have the idea about tags, and they have nothing to do with getting your program running and everything to do with helping us to be able to read your posts and your code.

    Please re-read collin's post above, and my signature below and then please edit your post above so that it's readable. One skill you'll need to be a successful programmer is to be able to follow directions.

    Much luck. :rolleyes:

Similar Threads

  1. Errors?
    By Jamison5213 in forum New To Java
    Replies: 4
    Last Post: 12-30-2009, 01:14 AM
  2. errors
    By ravikumar in forum Threads and Synchronization
    Replies: 3
    Last Post: 09-29-2009, 05:15 AM
  3. getting errors
    By ravikumar in forum Threads and Synchronization
    Replies: 3
    Last Post: 08-23-2009, 03:50 PM
  4. Errors.
    By rocky in forum New To Java
    Replies: 4
    Last Post: 04-09-2009, 09:05 AM
  5. Replies: 3
    Last Post: 03-08-2009, 02:51 AM

Posting Permissions

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