📄 salelist.java
字号:
import java.text.NumberFormat;
import java.util.*;
public class SaleList {
/**
* list of sale card
*/
private static LinkedList<Card> saleList = new LinkedList<Card> ();
/**
* a card in the list
*/
private static Card card;
/**
* to sale a kind card
* @param name String
* @param quantity int
* @param stuffName String
* @param price double
*/
public static void saleCard(String stuffName, String index, int quantity) throws
Exception {
card = CardList.getCard(index);
card.setSalesInfo(quantity,stuffName);
Card c = new Card(stuffName, index, card.getName(), quantity, card.getPrice());
saleList.add(c);
}
/**
* get the information of the salelist
* @return String
*/
public static String print() {
String list = "";
Card c = null;
if (saleList != null) {
for (int i = 0; i < saleList.size(); i++) {
String s;
if (i < 10) {
s = "c00" + i;
}
else if (i >= 0 && i < 100) {
s = "c0" + i;
}
else {
s = "c" + i;
}
c = saleList.get(i);
Double fee = c.getQuantity()*c.getPrice();
NumberFormat f = NumberFormat.getInstance();
f.setMinimumFractionDigits(2);
String f1 = f.format(fee);
list +=
s + " " + c.getId() + " " + c.getStuffName() + " " +
c.getQuantity() + " * $ " +
c.getPrice() + " = $ " + f1 +
"\r\n";
}
}
return list;
}
public static int getSize() {
return saleList.size();
}
/**
* get the card name in the specified position of the salelist
* @param i int
* @return Card
*/
public static String getSaleCardName(int i) {
return saleList.get(i).getName();
}
/**
* get the card quantity in the specific position of the salelist
* @param i int
* @return int
*/
public static int getSaleQuantity(String code) {
int quantity = 0;
for (int i = 0; i < saleList.size(); i++) {
Card c = saleList.get(i);
if (c.getId().equals(code)) {
quantity += c.getQuantity();
}
}
return quantity;
}
/**
* contains the Card named name YES OR NO
* @param name String
* @return boolean
*/
public static boolean contains(String code) {
for (int i = 0; i < saleList.size(); i++) {
if (saleList.get(i).getId().equals(code)) {
return true;
}
}
return false;
}
/**
* Remove card from sale list and return it
*/
public static Card remove(){
return saleList.remove();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -