现在的作业的题目都是 给 我提供 一个class 文件 和一个未完成的java 文件
其中 java文件要使用 那个class文件
但是出问题了
比喻说
一个文件里面有一个A.class 和B.java
B 要用到A.class 我直接使用的时候会提示 找不到 class A
A.class 和B.java 在同一个目录下
即使我 import A; 也不行
怎么办!!!!!!!!!!
其中 java文件要使用 那个class文件
但是出问题了
比喻说
一个文件里面有一个A.class 和B.java
B 要用到A.class 我直接使用的时候会提示 找不到 class A
A.class 和B.java 在同一个目录下
即使我 import A; 也不行
怎么办!!!!!!!!!!
而且A 和 B 的结构也很简单 就是 B中 new 一个 class A
再使用 A 中的一些简单函数
在 D:/sss/
下
就在classpath 里面加 “D:/sss/;” 吗?
classpath要把当前目录.;添上
现在就只有 一个A.class 和B.java
从网上下载下来的
import java.io.*;
import java.util.*;
/**
* <p>This class is to simulate a shopint car </p>
* <p>This class will give the user 5 choice to
* show the different informations,such as the ID,telephone ,etc
* </p>
*
* <p>Copyright: JESSE (c) 2006</p>
*
* <p>Company: JESSE_SOFTWARE </p>
*
* @author JESSE8013
* @version 1.0
*/
public class ShoppingCartApplication { 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 ShoppingCart cart; /* DOCUMENT THIS PUBLIC METHOD */
/**first initiate the class ShoppingApplication .
* and then invoke the run function
* IOException is thrown when error happened
*
*
*/
public static void main(String[] args) throws IOException { ShoppingCartApplication application = new ShoppingCartApplication(); application.run();
}
/**
* give the user four chances
* and input 0 to end the function
* @param cart the Object of class Shopping
*
*/
private void run() throws IOException { cart = new ShoppingCart(); int choice = getChoice(); while (choice != 0) { if (choice == 1) {
cart.addProduct(readProduct());
} else if (choice == 2) {
stdOut.println(cart.toString());
} else if (choice == 3) {
stdOut.println(cart.getTotalValue());
} choice = getChoice();
}
} private int getChoice() throws IOException { do { int input; try {
stdErr.println();
stdErr.print("[0] Quit\n"
+ "[1] Add Product\n"
+ "[2] Display Products\n"
+ "[3] Display Total\n"
+ "choice>");
stdErr.flush(); input = Integer.parseInt(stdIn.readLine()); if (0 <= input && 3 >= input) { return input; } else {
stdErr.println("Invalid choice: " + input);
}
} catch (NumberFormatException nfe) {
stdErr.println(nfe);
} }while (true);
}
/**
* make user to input a string while the model is
* like [name]_[quantity]_[price]
* use the StringTokenizer to decompound it into
* three part. and the sencond part should be int and not less 0
* and the the third part-the price shouble be double no less than 0
* else a wrong message vill output
* NumberOfFormat Exception will be catched
*
*
* @return return a instanced class Product
* @throws IOException
*/
private Product readProduct() throws IOException {
final String DELIM = "_";
String name = "";
int quantity = 0;
double price = 0.0;
String productModel=new String("[name]_[quanity]_[price]");
do {
stdOut.print(productModel);
stdOut.flush();
String inputProduct=stdIn.readLine();
StringTokenizer stringTokenizer=new StringTokenizer(inputProduct,DELIM);
if(stringTokenizer.countTokens()!=3){
stdOut.println("Invalide input,product should like this"+productModel);
stdOut.flush();
}
else{
name=stringTokenizer.nextToken();
try{
quantity=Integer.parseInt(stringTokenizer.nextToken());
price=Double.parseDouble(stringTokenizer.nextToken());
if(quantity<0||price<0){
if(quantity<0)
stdOut.println("Quantity should not less than 0");
if(price<0)
stdOut.println("price should not less than 0");
}
else
return new Product(name, quantity, price);
}
catch(NumberFormatException e){
stdErr.println(e.toString());
}
}
}
while(true);
}
}
反编译 是可以
但这总是麻烦
难道 给一个class 文件 就不能使用吗???