我一直在关注一个已经开始通过Sam自学java的java教程,虽然我已经复制了这个以确保我可以在开始改变之前运行它并使其成为我自己的,不会跑,我不知道为什么。如果你们其中一个人/女孩可以提供帮助,我将不胜感激。我已将我的java类放在正确的包中,但它没有运行。感谢。
Created dir: I:\Year 2\Java\NetBeansProjects\Portfolio 1\build
Updating property file: I:\Year 2\Java\NetBeansProjects\Portfolio 1\build\built-jar.properties
Created dir: I:\Year 2\Java\NetBeansProjects\Portfolio 1\build\classes
Created dir: I:\Year 2\Java\NetBeansProjects\Portfolio 1\build\empty
Created dir: I:\Year 2\Java\NetBeansProjects\Portfolio 1\build\generated-sources\ap-source-output
Compiling 3 source files to I:\Year 2\Java\NetBeansProjects\Portfolio 1\build\classes
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:14: error: ')' expected
store.addItem("C01", "MUG, "9.99", "150");
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:14: error: not a statement
store.addItem("C01", "MUG, "9.99", "150");
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:14: error: ';' expected
store.addItem("C01", "MUG, "9.99", "150");
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:14: error: unclosed string literal
store.addItem("C01", "MUG, "9.99", "150");
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: illegal character: '\u201c'
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: ';' expected
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: illegal character: '\u201d'
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: ';' expected
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: illegal character: '\u201c'
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: illegal character: '\u201d'
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: illegal character: '\u201c'
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: illegal character: '\u201d'
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: illegal character: '\u201c'
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:16: error: illegal character: '\u201d'
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: illegal character: '\u201c'
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: ';' expected
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: illegal character: '\u201d'
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: ';' expected
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: illegal character: '\u201c'
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: ';' expected
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: illegal character: '\u201d'
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: not a statement
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: illegal character: '\u201c'
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: illegal character: '\u201d'
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: illegal character: '\u201c'
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:17: error: illegal character: '\u201d'
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
I:\Year 2\Java\NetBeansProjects\Portfolio 1\src\Package1\Giftshop.java:18: error: ';' expected
store.sort());
27 errors
I:\Year 2\Java\NetBeansProjects\Portfolio 1\nbproject\build-impl.xml:923: The following error occurred while executing this line:
I:\Year 2\Java\NetBeansProjects\Portfolio 1\nbproject\build-impl.xml:263: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
package com.jackson.ecommerce;
import java.util.*;
public class Item implements Comparable {
private String id;
private String name;
private double retail;
private int quantity;
private double price;
Item(String idIn, String nameIn, String retailIn, String quanIn) {
id = idIn;
name = nameIn;
retail = Double.parseDouble(retailIn);
if (quantity > 400)
price = retail * 5D;
else if (quantity > 200)
price = retail * .6D;
else
price = retail * .7D;
price = Math.floor( price * 100 + .5) / 100;
}
public int compareTo(Object obj) {
Item temp = (Item)obj;
if (this.price < temp.price)
return 1;
return 0;
}
public String getId(){
return id;
}
public String getName(){
return name;
}
public double GetRetail(){
return retail;
}
public int getQuantity(){
return quantity;
}
public double getPrice(){
return price;
}
}
package com.jackson.ecommerce;
import java.util.*;
public class Storefront {
private LinkedList catalog = new LinkedList();
public void addItem(String id, String name, String price, String quant){
Item it = new Item(id, name, price, quant);
catalog.add(it);
}
public Item getItem(int i){
return (Item)catalog.get(i);
}
public int getSize(){
return catalog.size();
}
public void sort() {
Collections.sort(catalog);
}
package Package1;
import com.jackson.ecommerce.*;
public class Giftshop {
public static void main(String[] arguments){
Storefront store = new Storefront();
store.addItem("C01", "MUG, "9.99", "150");
store.addItem("C02", "LG MUG", "12.99", "82");
store.addItem(“C03”, “MOUSEPAD”, “10.49”, “800”);
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
store.sort());
for (int i = 0; i < store.getSize(); i++) {
Item show = (Item)store.getItem(i);
System.out.println( show.getId() +
show.getName() +
show.getRetail() +
show.getPrice() +
show.getQuantity());
}
}
}
答案 0 :(得分:6)
这是因为代码使用的是“
UNICODE 字符,而不是 ASCII 字符,不能用于表示字符串文字强>
见这里:
store.addItem(“C03“, “MOUSEPAD”, “10.49”, “800”);
store.addItem(“D01”, “T SHIRT”, “16.99”, “90”);
将其更改为"
。