Results 1 to 6 of 6
Thread: Getting errors
- 01-15-2010, 04:13 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 16
- Rep Power
- 0
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;
}
}
}
}
-
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!
- 01-15-2010, 04:47 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 16
- Rep Power
- 0
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
- 01-15-2010, 05:09 AM #4
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
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.
- 01-15-2010, 05:37 AM #5
Member
- Join Date
- Dec 2009
- Posts
- 16
- Rep Power
- 0
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());
}
}
}
}
-
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
-
Errors?
By Jamison5213 in forum New To JavaReplies: 4Last Post: 12-30-2009, 12:14 AM -
errors
By ravikumar in forum Threads and SynchronizationReplies: 3Last Post: 09-29-2009, 04:15 AM -
getting errors
By ravikumar in forum Threads and SynchronizationReplies: 3Last Post: 08-23-2009, 02:50 PM -
Errors.
By rocky in forum New To JavaReplies: 4Last Post: 04-09-2009, 08:05 AM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks