Guest User

Untitled

a guest
May 26th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. package com.sample.springboot;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class BookStore { //★テスト対象クラス
  7.  
  8. private List<Cart> cart = new ArrayList<Cart>();
  9. private List<Book> books = new ArrayList<Book>();
  10.  
  11. public void addToCart(Book book, int i) {
  12. books.add(book);
  13. Cart item = new Cart(book, i);
  14. cart.add(item);
  15. }
  16.  
  17. public int getTotalPrice() {
  18. int sum = 0;
  19. for (Cart Cart : cart) {
  20. int priceOne = Cart.getBook().getPrice();
  21. sum += priceOne * Cart.getCount();
  22. }
  23. return sum;
  24. }
  25.  
  26. public Book get(int i) {
  27. return books.get(i);
  28. }
  29. }
  30.  
  31. class Cart { //★テスト対象クラスが利用しているクラス
  32. private Book book;
  33. private int count;
  34.  
  35. public Book getBook() {
  36. return book;
  37. }
  38.  
  39. public void setBook(Book book) {
  40. this.book = book;
  41. }
  42.  
  43. public int getCount() {
  44. return count;
  45. }
  46.  
  47. public void setCount(int count) {
  48. this.count = count;
  49. }
  50.  
  51. public Cart(Book book, int count) {
  52. super();
  53. this.book = book;
  54. this.count = count;
  55. }
  56. }
  57.  
  58. class Book { //★テスト対象クラスが利用しているクラス
  59.  
  60. private String title;
  61. private int price;
  62. private Author author;
  63.  
  64. public String getTitle() {
  65. return title;
  66. }
  67.  
  68. public void setTitle(String title) {
  69. this.title = title;
  70. }
  71.  
  72. public int getPrice() {
  73. return price;
  74. }
  75.  
  76. public void setPrice(int price) {
  77. this.price = price;
  78. }
  79.  
  80. public Author getAuthor() {
  81. return author;
  82. }
  83.  
  84. public void setAuthor(Author author) {
  85. this.author = author;
  86. }
  87.  
  88. public Book() {
  89. super();
  90. }
  91.  
  92. public Book(int price) {
  93. this();
  94. this.price = price;
  95. }
  96. }
  97.  
  98. class Author { //★テスト対象クラスが利用しているクラス
  99.  
  100. private String firstName;
  101. private String lastName;
  102.  
  103. public String getFirstName() {
  104. return firstName;
  105. }
  106.  
  107. public void setFirstName(String firstName) {
  108. this.firstName = firstName;
  109. }
  110.  
  111. public String getLastName() {
  112. return lastName;
  113. }
  114.  
  115. public void setLastName(String lastName) {
  116. this.lastName = lastName;
  117. }
  118.  
  119. }
Add Comment
Please, Sign In to add comment