-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCart.java
More file actions
49 lines (41 loc) · 1.17 KB
/
Cart.java
File metadata and controls
49 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.ArrayList;
/*
Written by: Emil Ljung
Project: Arbetsprov
OS: Windows 7 Ultimate 64-bit, Service Pack 1
Platform: NetBeans IDE 8.1
Java version: Java 8 Update 73
*/
public class Cart
{
private ArrayList<Book> books;
private ArrayList<Integer> nrOfBooks; //Sort this one correctly if books is being sorted!
public Cart()
{
//Amount of the book books.get(i) is nrOfBooks.get(i)
this.books = new ArrayList<>();
this.nrOfBooks = new ArrayList<>();
}
public void add(Book book, int amount)
{
this.books.add(book);
this.nrOfBooks.add(amount);
}
public void remove(int i)
{
this.books.remove(i);
this.nrOfBooks.remove(i);
}
public void setNrOfBook(int i, int amount)
{
this.nrOfBooks.set(i, amount);
}
public Book[] getBookArray()
{
return this.books.toArray(new Book[this.books.size()]);
}
public Integer[] getNrOfBooksArray()
{
return this.nrOfBooks.toArray(new Integer[this.nrOfBooks.size()]);
}
}