Em xin loi truoc vi khong viet co dau duoc du` em da~ bat vietkey
em co cai code muon xin moi nguoi gui y giup gium em
trong phan product thi em lam ra roi nhung trong phan order thi em chi lam` ra Order [productId=[1, 2, 3, 4], quantity=[4, 3, 2, 1]] con phan Order [productId=[113489, 201934, 3488, 84432], quantity=[11, 22, 12, 3]] thi em lam hoai khong ra
em da su dung rat nhiu cach khac nhau nhung van khong ra duoc.
cam on moi nguoi.
em co cai code muon xin moi nguoi gui y giup gium em
public void saveToFile(String filename)
{
File file = new File(filename);
try
{
PrintWriter print = new PrintWriter(file);
int theP = productId.size();
for(int i=0; i < theP; i++)
{
print.println(productId.get(i).toString());
}
int theQ = productId.size();
for(int i=0; i < theQ; i++)
{
print.println(quantity.get(i).toString());
}
print.close();
}
catch (FileNotFoundException e)
{
System.out.println("Unable to load product from " + file + ".");
}
}
{
File file = new File(filename);
try
{
PrintWriter print = new PrintWriter(file);
int theP = productId.size();
for(int i=0; i < theP; i++)
{
print.println(productId.get(i).toString());
}
int theQ = productId.size();
for(int i=0; i < theQ; i++)
{
print.println(quantity.get(i).toString());
}
print.close();
}
catch (FileNotFoundException e)
{
System.out.println("Unable to load product from " + file + ".");
}
}
public class Tester2
{
public static void main(String[] args)
{
Product p1 = new Product();
p1.loadFromFile("Monitor.txt");
System.out.println("Actual: " + p1.toString());
System.out.println("Expected: Product [id=12345, name=Monitor, description=A freakin great monitor!]");
p1.setId(11111);
p1.setName("another product");
p1.setDescription("Description of another product!");
p1.saveToFile("SaveTest1.pr");
p1 = null;
p1 = new Product();
p1.loadFromFile("SaveTest1.pr");
System.out.println("Actual: " + p1.toString());
System.out.println("Expected: Product [id=11111, name=another product, description=Description of another product!]");
Order o1 = new Order();
o1.loadFromFile("Order1.or");
System.out.println("Actual: " + o1.toString());
System.out.println("Expected: Order [productId=[113489, 201934, 3488, 84432], quantity=[11, 22, 12, 3]]");
o1 = null;
o1 = new Order();
o1.addProduct(1, 4);
o1.addProduct(2, 3);
o1.addProduct(3, 2);
o1.addProduct(4, 1);
o1.saveToFile("SaveTest2.or");
o1 = null;
o1 = new Order();
o1.loadFromFile("SaveTest2.or");
System.out.println("Actual: " + o1.toString());
System.out.println("Expected: Order [productId=[1, 2, 3, 4], quantity=[4, 3, 2, 1]]");
Order o2 = new Order();
System.out.print("Actual: ");
o2.loadFromFile("BadOrder.or");
System.out.println("Expected: Unable to load order from BadOrder.or.");
Product p2 = new Product();
System.out.print("Actual: ");
p2.loadFromFile("BadProduct.pr");
System.out.println("Expected: Unable to load product from BadProduct.pr.");
}
}
{
public static void main(String[] args)
{
Product p1 = new Product();
p1.loadFromFile("Monitor.txt");
System.out.println("Actual: " + p1.toString());
System.out.println("Expected: Product [id=12345, name=Monitor, description=A freakin great monitor!]");
p1.setId(11111);
p1.setName("another product");
p1.setDescription("Description of another product!");
p1.saveToFile("SaveTest1.pr");
p1 = null;
p1 = new Product();
p1.loadFromFile("SaveTest1.pr");
System.out.println("Actual: " + p1.toString());
System.out.println("Expected: Product [id=11111, name=another product, description=Description of another product!]");
Order o1 = new Order();
o1.loadFromFile("Order1.or");
System.out.println("Actual: " + o1.toString());
System.out.println("Expected: Order [productId=[113489, 201934, 3488, 84432], quantity=[11, 22, 12, 3]]");
o1 = null;
o1 = new Order();
o1.addProduct(1, 4);
o1.addProduct(2, 3);
o1.addProduct(3, 2);
o1.addProduct(4, 1);
o1.saveToFile("SaveTest2.or");
o1 = null;
o1 = new Order();
o1.loadFromFile("SaveTest2.or");
System.out.println("Actual: " + o1.toString());
System.out.println("Expected: Order [productId=[1, 2, 3, 4], quantity=[4, 3, 2, 1]]");
Order o2 = new Order();
System.out.print("Actual: ");
o2.loadFromFile("BadOrder.or");
System.out.println("Expected: Unable to load order from BadOrder.or.");
Product p2 = new Product();
System.out.print("Actual: ");
p2.loadFromFile("BadProduct.pr");
System.out.println("Expected: Unable to load product from BadProduct.pr.");
}
}
Actual: Product [id=0, name=null, description=null]
Expected: Product [id=12345, name=Monitor, description=A freakin great monitor!]
Actual: Product [id=11111, name=another product, description=Description of another product!]
Expected: Product [id=11111, name=another product, description=Description of another product!]
Actual: Order [productId=[], quantity=[]]
Expected: Order [productId=[113489, 201934, 3488, 84432], quantity=[11, 22, 12, 3]]
Actual: Order [productId=[1, 2, 3, 4], quantity=[4, 3, 2, 1]]
Expected: Order [productId=[1, 2, 3, 4], quantity=[4, 3, 2, 1]]
Actual: Expected: Unable to load order from BadOrder.or.
Actual: Expected: Unable to load product from BadProduct.pr.
Expected: Product [id=12345, name=Monitor, description=A freakin great monitor!]
Actual: Product [id=11111, name=another product, description=Description of another product!]
Expected: Product [id=11111, name=another product, description=Description of another product!]
Actual: Order [productId=[], quantity=[]]
Expected: Order [productId=[113489, 201934, 3488, 84432], quantity=[11, 22, 12, 3]]
Actual: Order [productId=[1, 2, 3, 4], quantity=[4, 3, 2, 1]]
Expected: Order [productId=[1, 2, 3, 4], quantity=[4, 3, 2, 1]]
Actual: Expected: Unable to load order from BadOrder.or.
Actual: Expected: Unable to load product from BadProduct.pr.
em da su dung rat nhiu cach khac nhau nhung van khong ra duoc.
cam on moi nguoi.