Advertisement
lashrone1

lb3

Dec 11th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.02 KB | None | 0 0
  1.  
  2. public class Movie {
  3. public String movieId;
  4. public String year = "0";
  5. public String title;
  6. public String genrs;
  7.  
  8.  
  9. public void setGenrs(String genrs) {
  10. this.genrs = genrs;
  11. }
  12.  
  13. public void setYear(String year) {
  14. this.year = year;
  15. }
  16.  
  17. public void setMovieId(String movieId) {
  18. this.movieId = movieId;
  19. }
  20.  
  21. public void setTitle(String title) {
  22. this.title = title;
  23. }
  24.  
  25. public String getMovieId() {
  26. return movieId;
  27. }
  28.  
  29. public String getYear() {
  30. return year;
  31. }
  32.  
  33. public String getGenrs() {
  34. return genrs;
  35. }
  36.  
  37. public String getTitle() {
  38. return title;
  39. }
  40.  
  41. @Override
  42. public String toString(){
  43. return "\nID "+getMovieId()+"::Title "+getTitle()+"::Year "+getYear()+"::Genrs "+getGenrs();
  44. }
  45.  
  46.  
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53. import org.omg.IOP.Encoding;
  54.  
  55. import javax.xml.soap.Text;
  56. import java.io.*;
  57. import java.nio.ByteBuffer;
  58. import java.nio.file.attribute.FileTime;
  59. import java.util.*;
  60. import java.util.stream.Collectors;
  61. import java.util.zip.ZipEntry;
  62. import java.util.zip.ZipInputStream;
  63. import java.util.zip.ZipOutputStream;
  64.  
  65.  
  66.  
  67.  
  68. public class Main {
  69.  
  70.  
  71.  
  72. static List<Movie> empList = new ArrayList<>();
  73. static void menu(){
  74.  
  75.  
  76. boolean q = true;
  77. while(q){
  78. Scanner sc = new Scanner(System.in);
  79. System.out.println();
  80. System.out.println("Основні можливості системи:\n" +
  81. "1. Додати видання до реєстру;\n" +
  82. "2. Видалити видання із реєстру;\n" +
  83. "3. Отримати список усіх видань, що містяться у реєстрі;\n" +
  84. "4. Отримати список усіх видань із реєстру за жанром, або спрямованістю;\n" +
  85. "5. Отримати список усіх видань із реєстру за роком;\n" +
  86. "6. Зберегти реєстр до сховища (текстовий файл);\n" +
  87. "7. Отримати реєстр із сховища (текстового файлу).");
  88. int answer = sc.nextInt();
  89.  
  90. switch (answer) {
  91.  
  92. case 1: {
  93. Movie mov = new Movie();
  94. Scanner c = new Scanner(System.in);
  95. int id = Integer.parseInt(empList.get(empList.size() - 1).getMovieId()) + 2;
  96. String id1 = String.valueOf(id);
  97. mov.setMovieId(id1);
  98. System.out.println("tilte: ");
  99. String title = c.nextLine();
  100. mov.setTitle(title);
  101. System.out.println("Year: ");
  102. String year = c.nextLine();
  103. mov.setYear(year);
  104. System.out.println("Genrs: ");
  105. String gen = c.nextLine();
  106. mov.setGenrs(gen);
  107.  
  108. empList.add(mov);
  109. break;
  110. }
  111.  
  112. case 2: {
  113. Scanner c = new Scanner(System.in);
  114. System.out.println("Size: " + empList.size());
  115. System.out.println("index: ");
  116. int i = c.nextInt();
  117. empList.remove(i-1);
  118. break;
  119. }
  120.  
  121. case 3: {
  122. System.out.println(empList);
  123. break;
  124. }
  125.  
  126. case 4: {
  127. Scanner c = new Scanner(System.in);
  128. System.out.println("Genrs: ");
  129. String gern = c.nextLine();
  130. for (int a = 0; a < empList.size() - 1; a++) {
  131. if (empList.get(a).getGenrs().equals(gern)) {
  132. System.out.println(empList.get(a));
  133. }
  134. }
  135. break;
  136. }
  137.  
  138. case 5: {
  139. Scanner c = new Scanner(System.in);
  140. System.out.println("Year: ");
  141. String year = c.nextLine();
  142. for (int a = 0; a < empList.size() - 1; a++) {
  143. if (empList.get(a).getYear().equals(year)) {
  144. System.out.println(empList.get(a));
  145. }
  146. }
  147. break;
  148. }
  149. case 6:{
  150. try {
  151. ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("name.zip"));
  152. ZipEntry entry = new ZipEntry("test.csv");
  153.  
  154. zos.putNextEntry(entry);
  155.  
  156. String com = ",";
  157. String nl = "\n";
  158.  
  159. for (int i = 0; i < empList.size();i++){
  160. byte[] bytes = empList.get(i).getMovieId().getBytes();
  161. byte[] bytes1 = empList.get(i).getTitle().getBytes();
  162. byte[] bytes2 = empList.get(i).getYear().getBytes();
  163. byte[] bytes3 = empList.get(i).getGenrs().getBytes();
  164. byte[] b = com.getBytes();
  165. byte[] n = nl.getBytes();
  166. zos.write(bytes);
  167. zos.write(b);
  168. zos.write(bytes1);
  169. zos.write(b);
  170. zos.write(bytes2);
  171. zos.write(b);
  172. zos.write(bytes3);
  173. zos.write(n);
  174. }
  175. zos.close();
  176. } catch (FileNotFoundException e) {
  177. e.printStackTrace();
  178. } catch (IOException e) {
  179. e.printStackTrace();
  180. }
  181. break;
  182. }
  183.  
  184. case 7: {
  185. try {
  186. ZipInputStream zis = new ZipInputStream(new FileInputStream("Movies.zip"));
  187. ZipEntry entry;
  188. String line = null;
  189. int index = 0;
  190.  
  191. Scanner scanner = new Scanner(zis);
  192. Scanner valueScanner = null;
  193. zis.getNextEntry();
  194. scanner.nextLine();
  195. while (scanner.hasNextLine()) {
  196. valueScanner = new Scanner(scanner.nextLine());
  197. valueScanner.useDelimiter(",");
  198.  
  199. Movie movie = new Movie();
  200.  
  201. while (valueScanner.hasNext()) {
  202. String data = valueScanner.next();
  203. if (index == 0){
  204. movie.setMovieId(data);
  205. }
  206. else if (index == 1){
  207. movie.setTitle(data);
  208. }
  209. else if (index == 2){
  210. movie.setGenrs(data);
  211. }
  212. index++;
  213. }
  214. index = 0;
  215. empList.add(movie);
  216. }
  217.  
  218. scanner.close();
  219.  
  220. zis.close();
  221. System.out.println(empList);
  222. } catch (IOException e) {
  223. e.printStackTrace();
  224. } catch (Exception ex) {
  225. }
  226. break;
  227. }
  228.  
  229.  
  230. default:{
  231. System.out.println("Оберіть можливість із списку 1-9!");
  232. break;
  233. }
  234. }
  235. }
  236.  
  237. }
  238.  
  239. static void num_2(){
  240. try (DataInputStream dataInputStream = new DataInputStream(new FileInputStream("movies.zip"))){
  241.  
  242.  
  243. float f = dataInputStream.readFloat();
  244. System.out.printf("0x%08X", Float.floatToRawIntBits(f));
  245. System.out.println();
  246.  
  247.  
  248. byte [] b = new byte[2];
  249. b[0] = dataInputStream.readByte();
  250. b[1] = dataInputStream.readByte();
  251. System.out.println(b[0]/10+ "," + b[1]);
  252.  
  253.  
  254.  
  255. dataInputStream.skipBytes(2);
  256.  
  257. b[0] = dataInputStream.readByte();
  258. b[1] = dataInputStream.readByte();
  259. System.out.println(b[0]+ b[1]);
  260.  
  261. b[0] = dataInputStream.readByte();
  262. b[1] = dataInputStream.readByte();
  263.  
  264.  
  265.  
  266. StringBuffer buffer = new StringBuffer();
  267. for(int i=0; i < b.length; i++){
  268. buffer.append(Character.forDigit((b[i] >> 4) & 0xF, 16));
  269. buffer.append(Character.forDigit((b[i] & 0xF), 16));
  270.  
  271. }
  272. System.out.println(buffer);
  273.  
  274. b[0] = dataInputStream.readByte();
  275. b[1] = dataInputStream.readByte();
  276.  
  277. for(int i=0; i < b.length; i++){
  278. buffer.append(Character.forDigit((b[i] >> 4) & 0xF, 16));
  279. buffer.append(Character.forDigit((b[i] & 0xF), 16));
  280.  
  281. }
  282. System.out.println(buffer);
  283.  
  284. dataInputStream.skipBytes(4);
  285.  
  286. int com = dataInputStream.readInt();
  287. System.out.println(Integer.reverseBytes(com));
  288.  
  289. int uncom = dataInputStream.readInt();
  290. System.out.println(Integer.reverseBytes(uncom));
  291.  
  292. } catch (FileNotFoundException e) {
  293. e.printStackTrace();
  294. } catch (IOException e) {
  295. e.printStackTrace();
  296. }
  297.  
  298. }
  299.  
  300. public static void main(String[] args) {
  301.  
  302. menu();
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310. // String [] str = new String[4];
  311. // String s = empList.get(empList.size()-1).getTitle();
  312. // int a = 0;
  313. // for(int i=0;i<s.length();i++) {
  314. // if(Character.isDigit(s.charAt(i))) {
  315. // str[a] = String.valueOf(s.charAt(i));
  316. // a++;
  317. // }
  318. // }
  319. //
  320. // StringBuilder stringBuilder = new StringBuilder();
  321. // for (int i = 0; i < str.length; i++) {
  322. // stringBuilder.append(str[i]);
  323. // }
  324. // String aa = stringBuilder.toString();
  325. //
  326. // System.out.println(aa);
  327. // System.out.println(empList.get(1).getTitle());
  328. //
  329. //
  330. // for (Movie movie : empList) {
  331. // if (movie.getTitle().equals("Toy Story (1995)")) {
  332. // System.out.println(movie.toString());
  333. // }
  334. // }
  335. //
  336. //
  337. //
  338. //
  339. //
  340.  
  341.  
  342. // String data = empList.get(1).getTitle();
  343. // String [] str = new String[2];
  344. // int i = 0;
  345. // for (String retval : data.split("\\(")) {
  346. // str[i] = retval;
  347. // i++;
  348. // }
  349. //
  350. // data = str[1];
  351. // for (String retval : data.split("\\)")) {
  352. // str[1] = retval;
  353. // }
  354. // System.out.println(str[0] + " " +str[1]);
  355.  
  356. // try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("D:\\name.zip"));
  357. // FileInputStream fis = new FileInputStream("file.txt")) {
  358. //
  359. // ZipEntry entry = new ZipEntry("1.txt");
  360. // zos.putNextEntry(entry);
  361. // byte[] buffer = new byte[fis.available()];
  362. //
  363. // fis.read(buffer);
  364. // zos.write(buffer);
  365. // zos.closeEntry();
  366. // zos.close(); //обязательно, иначе в архив ничего не запишется ??????
  367. //
  368. // } catch (IOException ex) {}
  369. }
  370.  
  371. private static class ASCII {
  372. }
  373. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement