错误信息: 'class' or 'interface' expected 求助 最外面加上public class GourmetCoffee{//你的代码} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是实现的Runnable接口吗public interface Runnable{ public void run();}=====================================private void run() throws IOException=====================================面向对象的机制里不允许在继承或实现的过程中降低访问权限。 改成public void run() throws IOException import java.io.*;import java.util.*;import java.text.*;/** * This class implements a gourmet coffee system. * * @author Dracula * @version 1.1.0 * @see Product * @see Coffee * @see CoffeeBrewer * @see Catalog * @see OrderItem * @see Order * @see SalesFormatter * @see PlainTextSalesFormatter * @see HTMLSalesFormatter * @see XMLSalesFormatter */public class GourmetCoffee { private static BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); private static PrintWriter stdOut = new PrintWriter(System.out, true); private static PrintWriter stdErr = new PrintWriter(System.err, true); private Sales sales; private SalesFormatter salesFormatter; /** * Loads data into the catalog and starts the application. * * @param args String arguments. Not used. * @throws IOException if there are errors in the input. */ public static void main(String[] args) throws IOException { GourmetCoffee application = new GourmetCoffee(); application.run(); }// // /* single instance of this class */// static private GourmetCoffee singletonInstance = null;//// // /**// * Obtains the single instance of class GourmetCoffee// * // * @return the single instance of class GourmetCoffee// */// static public GourmetCoffee getSingletonInstance() {//// if (singletonInstance == null) {// singletonInstance = new GourmetCoffee();// }//// return singletonInstance;// } /** * Constructs a <code>GourmetCoffee</code> object and * initializes the catalog and sales data. * * @param initialCatalog a product catalog */ private GourmetCoffee() { sales = new Sales(); salesFormatter = PlainTextSalesFormatter.getSingletonInstance(); loadSales(loadCatalog()); } /** * Creates an empty catalog and then add products to it. * * @return a product catalog */ private Catalog loadCatalog() { Catalog catalog = new Catalog(); catalog.addProduct(new Coffee("C001", "Colombia, Whole, 1 lb", 17.99, "Colombia", "Medium", "Rich and Hearty", "Rich", "Medium", "Full")); catalog.addProduct(new Coffee("C002", "Colombia, Ground, 1 lb", 18.75, "Colombia", "Medium", "Rich and Hearty", "Rich", "Medium","Full")); catalog.addProduct(new Coffee("C003", "Italian Roasts, Whole, 1 lb", 16.80, "Latin American Blend", "Italian Roast", "Dark and heavy", "Intense", "Low", "Medium")); catalog.addProduct(new Coffee("C004", "Italian Roasts, Ground, 1 lb", 17.55, "Latin American Blend", "Italian Roast", "Dark and heavy", "Intense", "Low", "Medium")); catalog.addProduct(new Coffee("C005", "French Roasts, Whole, 1 lb", 16.80, "Latin American Blend", "French Roast", "Bittersweet, full intense", "Intense, full", "None", "Medium")); catalog.addProduct(new Coffee("C006", "French Roasts, Ground, 1 lb", 17.55, "Latin American Blend", "French Roast", "Bittersweet, full intense", "Intense, full", "None", "Medium")); catalog.addProduct(new Coffee("C007", "Guatemala, Ground, 1 lb", 17.99, "Guatemala", "Medium", "Rich and complex", "Spicy", "Medium to high", "Medium to full")); catalog.addProduct(new Coffee("C008", "Guatemala, Ground, 1 lb", 18.75, "Guatemala", "Medium", "Rich and complex", "Spicy", "Medium to high", "Medium to full")); catalog.addProduct(new Coffee("C009", "Guatemala, Whole, 1 lb", 19.99, "Sumatra", "Medium", "Vibrant and powdery", "Like dark chocolate", "Gentle", "Rich and full")); catalog.addProduct(new Coffee("C010", "Guatemala, Ground, 1 lb", 20.50, "Sumatra", "Medium", "Vibrant and powdery", "Like dark chocolate", "Gentle", "Rich and full")); catalog.addProduct(new Coffee("C011", "Special Blend, Whole, 1 lb", 16.80, "Latin American Blend", "Dark roast", "Full, roasted flavor", "Hearty", "Bold and rich", "Full")); catalog.addProduct(new Coffee("C012", "Special Blend, Ground, 1 lb", 17.55, "Latin American Blend", "Dark roast", "Full, roasted flavor", "Hearty", "Bold and rich", "Full")); catalog.addProduct(new CoffeeBrewer("B001", "Home Coffee Brewer", 150.00, "Brewer 100", "Pourover", 6)); catalog.addProduct(new CoffeeBrewer("B002", "Coffee Brewer, 2 Warmers", 200.00, "Brewer 200", "Pourover", 12)); catalog.addProduct(new CoffeeBrewer("B003", "Coffee Brewer, 3 Warmers", 280.00, "Brewer 210", "Pourover", 12)); catalog.addProduct(new CoffeeBrewer("B004", "Commercial Brewer, 20 cups", 380.00, "Quick Coffee 100", "Automatic", 20)); catalog.addProduct(new CoffeeBrewer("B005", "Commercial Brewer, 40 cups", 480.00, "Quick Coffee 200", "Automatic", 40)); catalog.addProduct(new Product("A001", "Almond Flavored Syrup", 9.00)); catalog.addProduct(new Product("A002", "Irish Creme Flavored Syrup", 9.00)); catalog.addProduct(new Product("A003", "Mint Flavored syrup", 9.00)); catalog.addProduct(new Product("A004", "Caramel Flavored Syrup", 9.00)); catalog.addProduct(new Product("A005", "Gourmet Coffee Cookies", 12.00)); catalog.addProduct(new Product("A006", "Gourmet Coffee Travel Thermo", 18.00)); catalog.addProduct(new Product("A007", "Gourmet Coffee Ceramic Mug", 8.00)); catalog.addProduct(new Product("A008", "Gourmet Coffee 12 Filters", 15.00)); catalog.addProduct(new Product("A009", "Gourmet Coffee 36 Filters", 45.00)); return catalog; } /** * Initializes the sales object. */ private void loadSales(Catalog catalog) { Order orderOne = new Order(); orderOne.addItem(new OrderItem(catalog.getProduct("C001"), 5)); sales.addOrder(orderOne); Order orderTwo = new Order(); orderTwo.addItem(new OrderItem(catalog.getProduct("C002"), 2)); orderTwo.addItem(new OrderItem(catalog.getProduct("A001"), 2)); sales.addOrder(orderTwo); Order orderThree = new Order(); orderThree.addItem(new OrderItem(catalog.getProduct("B002"), 1)); sales.addOrder(orderThree); } /** * Displays a menu of options and verifies the user's choice. * * @return an integer in the range [0,3] */ private int getChoice() throws IOException { int input; do { try { stdErr.println(); stdErr.print("[0] Quit\n" + "[1] Display sales (Plain Text)\n" + "[2] Display sales (HTML)\n" + "[3] Display sales (XML)\n" + "choice> "); stdErr.flush(); input = Integer.parseInt(stdIn.readLine()); stdErr.println(); if (0 <= input && 3 >= input) { break; } else { stdErr.println("Invalid choice: " + input); } } catch (NumberFormatException nfe) { stdErr.println(nfe); } } while (true); return input; } /** * Changes the sales formatter. * * @param newFormatter a sales formatter */ private void setSalesFormatter(SalesFormatter newFormatter){ salesFormatter = newFormatter; } /** * Displays the sales information in the current format. */ private void displaySales() { stdOut.println( salesFormatter.formatBorrowers(sales)); } } /** * Presents the user with a menu of options and executes the * selected task. */ private void run() throws IOException { int choice = getChoice(); while (choice != 0) { if (choice == 1) { setSalesFormatter( PlainTextSalesFormatter.getSingletonInstance()); } else if (choice == 2) { setSalesFormatter( HTMLSalesFormatter.getSingletonInstance()); } else if (choice == 3) { setSalesFormatter( XMLSalesFormatter.getSingletonInstance()); } choice = getChoice(); } }} jdk安装目录问题 如何得到open数量和close 数! 怎样使一个图形界面类关闭之后再进行后续的操作? 请问<jsp:forward> 如何改变url? 如何用java程序不去生成自增长的生成器 求救:如何从控制台退出程序 奇怪的线程控制问题。。。 使用hashMap 配合 lock 可以达到并发操作的时候数据不会乱吗 帮忙看下面的代码! java用的是unicode, c 用的哪种字符编码? JTextArea在JOptionPane.showMessage后,显示的字符可以更改删除的问题。 一个小问题,大家别让我拖到明年再解决。
public interface Runnable{
public void run();
}
=====================================
private void run() throws IOException
=====================================
面向对象的机制里不允许在继承或实现的过
程中降低访问权限。
改成public void run() throws IOException
import java.util.*;
import java.text.*;/**
* This class implements a gourmet coffee system.
*
* @author Dracula
* @version 1.1.0
* @see Product
* @see Coffee
* @see CoffeeBrewer
* @see Catalog
* @see OrderItem
* @see Order
* @see SalesFormatter
* @see PlainTextSalesFormatter
* @see HTMLSalesFormatter
* @see XMLSalesFormatter
*/
public class GourmetCoffee { private static BufferedReader stdIn =
new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter stdOut = new PrintWriter(System.out, true);
private static PrintWriter stdErr = new PrintWriter(System.err, true); private Sales sales; private SalesFormatter salesFormatter; /**
* Loads data into the catalog and starts the application.
*
* @param args String arguments. Not used.
* @throws IOException if there are errors in the input.
*/
public static void main(String[] args) throws IOException { GourmetCoffee application = new GourmetCoffee();
application.run(); }
//
// /* single instance of this class */
// static private GourmetCoffee singletonInstance = null;
//
//
// /**
// * Obtains the single instance of class GourmetCoffee
// *
// * @return the single instance of class GourmetCoffee
// */
// static public GourmetCoffee getSingletonInstance() {
//
// if (singletonInstance == null) {
// singletonInstance = new GourmetCoffee();
// }
//
// return singletonInstance;
// } /**
* Constructs a <code>GourmetCoffee</code> object and
* initializes the catalog and sales data.
*
* @param initialCatalog a product catalog
*/
private GourmetCoffee() { sales = new Sales();
salesFormatter = PlainTextSalesFormatter.getSingletonInstance(); loadSales(loadCatalog());
} /**
* Creates an empty catalog and then add products to it.
*
* @return a product catalog
*/
private Catalog loadCatalog() { Catalog catalog = new Catalog(); catalog.addProduct(new Coffee("C001", "Colombia, Whole, 1 lb", 17.99,
"Colombia", "Medium", "Rich and Hearty", "Rich",
"Medium", "Full"));
catalog.addProduct(new Coffee("C002", "Colombia, Ground, 1 lb", 18.75,
"Colombia", "Medium", "Rich and Hearty", "Rich",
"Medium","Full"));
catalog.addProduct(new Coffee("C003", "Italian Roasts, Whole, 1 lb",
16.80, "Latin American Blend", "Italian Roast",
"Dark and heavy", "Intense", "Low", "Medium"));
catalog.addProduct(new Coffee("C004", "Italian Roasts, Ground, 1 lb",
17.55, "Latin American Blend", "Italian Roast",
"Dark and heavy", "Intense", "Low", "Medium"));
catalog.addProduct(new Coffee("C005", "French Roasts, Whole, 1 lb",
16.80, "Latin American Blend", "French Roast",
"Bittersweet, full intense", "Intense, full", "None", "Medium"));
catalog.addProduct(new Coffee("C006", "French Roasts, Ground, 1 lb",
17.55, "Latin American Blend", "French Roast",
"Bittersweet, full intense", "Intense, full", "None", "Medium"));
catalog.addProduct(new Coffee("C007", "Guatemala, Ground, 1 lb", 17.99,
"Guatemala", "Medium", "Rich and complex", "Spicy",
"Medium to high", "Medium to full"));
catalog.addProduct(new Coffee("C008", "Guatemala, Ground, 1 lb", 18.75,
"Guatemala", "Medium", "Rich and complex", "Spicy",
"Medium to high", "Medium to full"));
catalog.addProduct(new Coffee("C009", "Guatemala, Whole, 1 lb", 19.99,
"Sumatra", "Medium", "Vibrant and powdery",
"Like dark chocolate", "Gentle", "Rich and full"));
catalog.addProduct(new Coffee("C010", "Guatemala, Ground, 1 lb", 20.50,
"Sumatra", "Medium", "Vibrant and powdery",
"Like dark chocolate", "Gentle", "Rich and full"));
catalog.addProduct(new Coffee("C011", "Special Blend, Whole, 1 lb",
16.80, "Latin American Blend", "Dark roast",
"Full, roasted flavor", "Hearty", "Bold and rich", "Full"));
catalog.addProduct(new Coffee("C012", "Special Blend, Ground, 1 lb",
17.55, "Latin American Blend", "Dark roast",
"Full, roasted flavor", "Hearty", "Bold and rich", "Full")); catalog.addProduct(new CoffeeBrewer("B001", "Home Coffee Brewer",
150.00, "Brewer 100", "Pourover", 6));
catalog.addProduct(new CoffeeBrewer("B002", "Coffee Brewer, 2 Warmers",
200.00, "Brewer 200", "Pourover", 12));
catalog.addProduct(new CoffeeBrewer("B003", "Coffee Brewer, 3 Warmers",
280.00, "Brewer 210", "Pourover", 12));
catalog.addProduct(new CoffeeBrewer("B004", "Commercial Brewer, 20 cups",
380.00, "Quick Coffee 100", "Automatic", 20));
catalog.addProduct(new CoffeeBrewer("B005", "Commercial Brewer, 40 cups",
480.00, "Quick Coffee 200", "Automatic", 40)); catalog.addProduct(new Product("A001", "Almond Flavored Syrup", 9.00));
catalog.addProduct(new Product("A002", "Irish Creme Flavored Syrup", 9.00));
catalog.addProduct(new Product("A003", "Mint Flavored syrup", 9.00));
catalog.addProduct(new Product("A004", "Caramel Flavored Syrup", 9.00));
catalog.addProduct(new Product("A005", "Gourmet Coffee Cookies", 12.00));
catalog.addProduct(new Product("A006", "Gourmet Coffee Travel Thermo", 18.00));
catalog.addProduct(new Product("A007", "Gourmet Coffee Ceramic Mug", 8.00));
catalog.addProduct(new Product("A008", "Gourmet Coffee 12 Filters", 15.00));
catalog.addProduct(new Product("A009", "Gourmet Coffee 36 Filters", 45.00)); return catalog;
} /**
* Initializes the sales object.
*/
private void loadSales(Catalog catalog) { Order orderOne = new Order(); orderOne.addItem(new OrderItem(catalog.getProduct("C001"), 5));
sales.addOrder(orderOne); Order orderTwo = new Order(); orderTwo.addItem(new OrderItem(catalog.getProduct("C002"), 2));
orderTwo.addItem(new OrderItem(catalog.getProduct("A001"), 2));
sales.addOrder(orderTwo); Order orderThree = new Order(); orderThree.addItem(new OrderItem(catalog.getProduct("B002"), 1));
sales.addOrder(orderThree);
}
* Displays a menu of options and verifies the user's choice.
*
* @return an integer in the range [0,3]
*/
private int getChoice() throws IOException { int input; do {
try {
stdErr.println();
stdErr.print("[0] Quit\n"
+ "[1] Display sales (Plain Text)\n"
+ "[2] Display sales (HTML)\n"
+ "[3] Display sales (XML)\n"
+ "choice> ");
stdErr.flush(); input = Integer.parseInt(stdIn.readLine()); stdErr.println(); if (0 <= input && 3 >= input) {
break;
} else {
stdErr.println("Invalid choice: " + input);
}
} catch (NumberFormatException nfe) {
stdErr.println(nfe);
}
} while (true); return input;
} /**
* Changes the sales formatter.
*
* @param newFormatter a sales formatter
*/
private void setSalesFormatter(SalesFormatter newFormatter){ salesFormatter = newFormatter;
} /**
* Displays the sales information in the current format.
*/
private void displaySales() { stdOut.println(
salesFormatter.formatBorrowers(sales));
} } /**
* Presents the user with a menu of options and executes the
* selected task.
*/
private void run() throws IOException { int choice = getChoice(); while (choice != 0) { if (choice == 1) { setSalesFormatter(
PlainTextSalesFormatter.getSingletonInstance());
} else if (choice == 2) { setSalesFormatter(
HTMLSalesFormatter.getSingletonInstance()); } else if (choice == 3) { setSalesFormatter(
XMLSalesFormatter.getSingletonInstance());
} choice = getChoice();
}
}
}