因此,我正在編寫一個編程類的代碼,用於模擬客戶可以購買產品並將其添加到購物車的網站。我製作了一個產品和購物車類。它們都在某個目錄中,並且它們的.class文件位於同一個包中。那麼爲什麼我在編譯我的Cart類時在產品上找不到符號?幫助PLZ!將ty「找不到符號」爲什麼?
車類:
package com.DownloadThis;
import java.util.ArrayList;
public class Cart {
private ArrayList<Product> myCart;
public Cart() {
myCart = new ArrayList<Product>();
}
public void addProduct(Product p) {
myCart.add(p);
}
public float getTotal() {
float totalPrice = 0;
for(int i = 0; i < myCart.size(); i++) {
Object obj = myCart.get(i);
Product p = (Product)obj;
totalPrice = totalPrice + p.getPrice();
}
return totalPrice;
}
public void addToCart(int product_id) {
}
}
產品類:
package com.DownloadThis;
import java.sql.*;
public class Product {
private String artist;
private String album;
private int year;
private String genre;
private float price;
private String albumart;
private String username;
private String password;
private Connection connection = null;
private ResultSet rs = null;
private Statement st = null;
public Product() {
}
public Product(String artist, String album, int year, String genre, float price, String albumart) {
this.artist = artist;
this.album = album;
this.year = year;
this.genre = genre;
this.price = price;
this.albumart = albumart;
}
public String getArtist() {
return this.artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getAlbum() {
return this.album;
}
public void setAlbum(String album) {
this.album = album;
}
public int getYear() {
return this.year;
}
public void setYear(int year) {
this.year = year;
}
public String getGenre() {
return this.genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public float getPrice() {
return this.price;
}
public void setPrice(float price) {
this.price = price;
}
public String getAlbumart() {
return this.albumart;
}
public void setFilename(String albumart) {
this.albumart = albumart;
}
}
你能發佈完整的錯誤? – kosa
...以及產生它的確切線 – Vlad
您是否在命令行上編譯?在日食? – thatidiotguy