Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.57 KB | None | 0 0
  1. package pkg;
  2. import pkg.Date;
  3.  
  4. public class Human {
  5. private String name;
  6. private String gendre;
  7. private String add;
  8. private Date birth;
  9.  
  10. public Human() {
  11. this.name = this.gendre = this.add = null;
  12. this.birth = new Date();
  13. }
  14.  
  15. public Human(String newName, String newGendre, String newAdd, Date newBirth) {
  16. this.name = newName;
  17. this.gendre = newGendre;
  18. this.add = newAdd;
  19. this.birth = newBirth;
  20. }
  21.  
  22. public void setValue(String newName, String newGendre, String newAdd, Date newBirth) {
  23. this.name = this.gendre = this.add = null;
  24. this.birth = newBirth;
  25. }
  26.  
  27. public String getName() {
  28. return this.name;
  29. }
  30.  
  31. public String getGendre() {
  32. return this.gendre;
  33. }
  34.  
  35. public String getAdd() {
  36. return this.add;
  37. }
  38.  
  39. public Date getBirth() {
  40. return this.birth;
  41. }
  42.  
  43. public void printType() {
  44. System.out.println("Classe: Human");
  45. }
  46. }
  47.  
  48.  
  49.  
  50.  
  51. package pkg;
  52. import java.util.Scanner;
  53.  
  54. public class Date {
  55. private byte day;
  56. private byte month;
  57. private int year;
  58.  
  59. public Date() {
  60. this.day = this.month = 0;
  61. this.year = 0;
  62. }
  63.  
  64. public Date(byte newDay, byte newMonth, int newYear) {
  65. this.day = newDay;
  66. this.month = newMonth;
  67. this.year = newYear;
  68. }
  69.  
  70. public void setValue(byte newDay, byte newMonth, int newYear) {
  71. this.day = newDay;
  72. this.month = newMonth;
  73. this.year = newYear;
  74. System.out.println("Modifica valori data avvenuta con successo.");
  75. }
  76.  
  77. public boolean equals(Date otherDate) {
  78. if (this.year == otherDate.year) {
  79. if (this.month == otherDate.month) {
  80. if (this.day == otherDate.day) {
  81. return true;
  82. }
  83. }
  84. }
  85. return false;
  86. }
  87.  
  88. public byte getDay() {
  89. return this.day;
  90. }
  91.  
  92. public byte getMonth() {
  93. return this.month;
  94. }
  95.  
  96. public int getYear() {
  97. return this.year;
  98. }
  99. }
  100.  
  101.  
  102.  
  103.  
  104. package pkg;
  105. import pkg.Human;
  106. import pkg.Date;
  107.  
  108. public class ClientP extends Human {
  109. private String id;
  110.  
  111. public ClientP() {
  112. super();
  113. this.id = null;
  114. }
  115.  
  116. public ClientP(String newName, String newGendre, String newAdd, Date newBirth, String newId) {
  117. super(newName, newGendre, newAdd, newBirth);
  118. this.id = newId;
  119. }
  120.  
  121. public void setValue(String newName, String newGendre, String newAdd, Date newBirth, String newId) {
  122. super.setValue(newName, newGendre, newAdd, newBirth);
  123. this.id = newId;
  124. }
  125.  
  126. public String getName() {
  127. return super.getName();
  128. }
  129.  
  130. public String getGendre() {
  131. return super.getGendre();
  132. }
  133.  
  134. public String getAdd() {
  135. return super.getAdd();
  136. }
  137.  
  138. public Date getBirth() {
  139. return super.getBirth();
  140. }
  141.  
  142. public String getId() {
  143. return this.id;
  144. }
  145.  
  146. public void printType() {
  147. System.out.println("Classe: ClientP");
  148. }
  149. }
  150.  
  151.  
  152.  
  153.  
  154. package pkg;
  155. import pkg.ClientP;
  156.  
  157. public class Doctor extends ClientP {
  158. private String spec;
  159.  
  160. public Doctor() {
  161. super();
  162. this.spec = null;
  163. }
  164.  
  165. public Doctor(String newName, String newGendre, String newAdd, Date newBirth,
  166. String newId, String newSpec) {
  167. super(newName, newGendre, newAdd, newBirth, newId);
  168. this.spec = newSpec;
  169. }
  170.  
  171. public void setValue(String newName, String newGendre, String newAdd, Date newBirth,
  172. String newId, String newSpec) {
  173. super.setValue(newName, newGendre, newAdd, newBirth, newId);
  174. this.spec = newSpec;
  175. }
  176.  
  177. public String getName() {
  178. return super.getName();
  179. }
  180.  
  181. public String getGendre() {
  182. return super.getGendre();
  183. }
  184.  
  185. public String getAdd() {
  186. return super.getAdd();
  187. }
  188.  
  189. public Date getBirth() {
  190. return super.getBirth();
  191. }
  192.  
  193. public String getId() {
  194. return super.getId();
  195. }
  196.  
  197. public String getSpec() {
  198. return this.spec;
  199. }
  200. }
  201.  
  202.  
  203.  
  204.  
  205. package pkg;
  206. import pkg.Date;
  207. import pkg.ClientP;
  208. import pkg.Doctor;
  209.  
  210. public class Invoice {
  211. private Date dateReg;
  212. private int number;
  213. private Doctor nameDoctor;
  214. private ClientP nameClient;
  215. private String desc;
  216. private int amount;
  217. private int vat;
  218.  
  219. public Invoice() {
  220. this.dateReg = new Date();
  221. this.number = 0;
  222. this.nameDoctor = new Doctor();
  223. this.nameClient = new ClientP();
  224. this.desc = null;
  225. this.amount = 0;
  226. this.vat = 0;
  227. }
  228.  
  229. public Invoice(Date newDate, int newNumber, Doctor newDoctor,
  230. ClientP newClient, String newDesc, int newAmount, int newVat) {
  231. this.dateReg = newDate;
  232. this.number = newNumber;
  233. this.nameDoctor = newDoctor;
  234. this.nameClient = newClient;
  235. this.desc = newDesc;
  236. this.amount = newAmount;
  237. this.vat = newVat;
  238. }
  239.  
  240. public void setValue(Date newDate, int newNumber, Doctor newDoctor,
  241. ClientP newClient, String newDesc, int newAmount, int newVat) {
  242. this.dateReg = newDate;
  243. this.number = newNumber;
  244. this.nameDoctor = newDoctor;
  245. this.nameClient = newClient;
  246. this.desc = newDesc;
  247. this.amount = newAmount;
  248. this.vat = newVat;
  249. }
  250.  
  251. public Date getDate() {
  252. return this.dateReg;
  253. }
  254.  
  255. public int getNumber() {
  256. return this.number;
  257. }
  258.  
  259. public Doctor getDoctor() {
  260. return this.nameDoctor;
  261. }
  262.  
  263. public ClientP getClient() {
  264. return this.nameClient;
  265. }
  266.  
  267. public String getDesc() {
  268. return this.desc;
  269. }
  270.  
  271. public int getAmount() {
  272. return this.amount;
  273. }
  274.  
  275. public int getVat() {
  276. return this.vat;
  277. }
  278. }
  279.  
  280.  
  281.  
  282.  
  283. import pkg.Date;
  284. import pkg.ClientP;
  285. import pkg.Doctor;
  286. import pkg.Invoice;
  287. import java.util.Scanner;
  288.  
  289. public class Main {
  290. private static ClientP recordClient(Scanner key) {
  291. String newName, newGendre, newAdd, newId;
  292. byte day, month;
  293. int year;
  294. Date newBirth;
  295. ClientP newClient;
  296. System.out.println("Inserire nome paziente:");
  297. newName = key.nextLine();
  298. System.out.println("Inserire genere paziente:");
  299. newGendre = key.nextLine();
  300. System.out.println("Inserire residenza:");
  301. newAdd = key.nextLine();
  302. System.out.println("Inserire giorno/mese/anno senza (GG MM AAAA) data di nascita:");
  303. day = key.nextByte();
  304. month = key.nextByte();
  305. year = key.nextInt();
  306. newBirth = new Date(day, month, year);
  307. System.out.println("Inserire ID paziente:");
  308. newId = key.nextLine();
  309. newId = key.nextLine();
  310. newClient = new ClientP(newName, newGendre, newAdd, newBirth, newId);
  311. return newClient;
  312. }
  313.  
  314. private static Doctor recordDoctor(Scanner key) {
  315. String newName, newGendre, newAdd, newId, newSpec;
  316. byte day, month;
  317. int year;
  318. Date newBirth;
  319. Doctor newDoctor;
  320. System.out.println("Inserire nome dottore:");
  321. newName = key.nextLine();
  322. System.out.println("Inserire genere dottore:");
  323. newGendre = key.nextLine();
  324. System.out.println("Inserire residenza:");
  325. newAdd = key.nextLine();
  326. System.out.println("Inserire giorno/mese/anno senza (GG MM AAAA) data di nascita:");
  327. day = key.nextByte();
  328. month = key.nextByte();
  329. year = key.nextInt();
  330. newBirth = new Date(day, month, year);
  331. System.out.println("Inserire ID dottore:");
  332. newId = key.nextLine();
  333. newId = key.nextLine();
  334. System.out.println("Inserire specializzazione:");
  335. newSpec = key.nextLine();
  336. newDoctor = new Doctor(newName, newGendre, newAdd, newBirth, newId, newSpec);
  337. return newDoctor;
  338. }
  339.  
  340. private static Doctor findDoctor(String newNameDoctor, Doctor[] doctor) {
  341. for (byte i = 0; i < doctor.length; ++i) {
  342. if (newNameDoctor.equalsIgnoreCase(doctor[i].getName()))
  343. return doctor[i];
  344. }
  345. return null;
  346. }
  347.  
  348. private static ClientP findClient(String newNameClient, ClientP[] client) {
  349. for (byte i = 0; i < client.length; ++i) {
  350. if (newNameClient.equalsIgnoreCase(client[i].getName()))
  351. return client[i];
  352. }
  353. return null;
  354. }
  355.  
  356. private static Invoice recordInvoice(Scanner key, ClientP[] client, Doctor[] doctor) {
  357. String newDesc, newNameDoctor, newNameClient;
  358. byte day, month;
  359. Date newDate;
  360. int year, newNumber, newAmount, newVat;
  361. Doctor newDoctor, resultD;
  362. ClientP newClient, resultC;
  363. Invoice newInvoice;
  364. System.out.println("Inserire giorno, mese e anno registrazione fattura" +
  365. " (GG/MM/AAAA):");
  366. day = key.nextByte();
  367. month = key.nextByte();
  368. year = key.nextInt();
  369. newDate = new Date(day, month, year);
  370. System.out.println("Inserire numero progressivo fattura:");
  371. newNumber = key.nextInt();
  372. System.out.println("Inserire nome dottore:");
  373. newNameDoctor = key.nextLine();
  374. newNameDoctor = key.nextLine();
  375. resultD = findDoctor(newNameDoctor, doctor);
  376. if (resultD == null) {
  377. System.out.println("Questo dottore non è registrato nel database.");
  378. return null;
  379. }
  380. newDoctor = resultD;
  381. System.out.println("Inserire nome paziente:");
  382. newNameClient = key.nextLine();
  383. resultC = findClient(newNameClient, client);
  384. if (resultC == null) {
  385. System.out.println("Questo paziente non è registrato nel database.");
  386. return null;
  387. }
  388. newClient = resultC;
  389. System.out.println("Inserire descrizione fattura:");
  390. newDesc = key.nextLine();
  391. System.out.println("Inserire totale fattura:");
  392. newAmount = key.nextInt();
  393. System.out.println("Inserire IVA:");
  394. newVat = key.nextInt();
  395. newInvoice = new Invoice(newDate, newNumber, newDoctor, newClient,
  396. newDesc, newAmount, newVat);
  397. return newInvoice;
  398. }
  399.  
  400. private static void printInvoice(Invoice invoice) {
  401. Date date;
  402. date = invoice.getDate();
  403. System.out.print(date.getDay() + " " + date.getMonth() + " " +
  404. date.getYear() + "\t");
  405. System.out.println(invoice.getNumber() + "\t" + invoice.getDoctor().getName() +
  406. "\t" + invoice.getClient().getName() + "\t" + invoice.getAmount());
  407. }
  408.  
  409. private static void showAllInvoices(Invoice[] invoice) {
  410. System.out.println("STORICO FATTURE:");
  411. for (byte i = 0; i < invoice.length; ++i) {
  412. printInvoice(invoice[i]);
  413. }
  414. }
  415.  
  416. private static void showInvoicesDate(Invoice[] invoice, Scanner key) {
  417. System.out.println("Inserire data per cercare fatture: (GG/MM/AAAA)");
  418. Date date;
  419. byte day, month;
  420. int year;
  421. boolean flag = false;
  422. day = key.nextByte();
  423. month = key.nextByte();
  424. year = key.nextInt();
  425. date = new Date(day, month, year);
  426. for (byte i = 0; i < invoice.length; ++i) {
  427. if (invoice[i].getDate().equals(date))
  428. printInvoice(invoice[i]);
  429. flag = true;
  430. }
  431. if (!flag)
  432. System.out.println("Non è stata registrata nessuna fattura nel" +
  433. " giorno " + day + " " + month + " " + year + ".");
  434. }
  435.  
  436. public static void main(String[] args) {
  437. System.out.println("Avvio programma");
  438. Scanner key = new Scanner(System.in);
  439. String bugfix;
  440. byte num, prompt;
  441. System.out.println("Quanti clienti si vogliono registrare?");
  442. num = key.nextByte();
  443. bugfix = key.nextLine();
  444. ClientP[] client = new ClientP[num];
  445. System.out.println("Registrazione pazienti in corso...");
  446. for (byte i = 0; i < num; ++i) {
  447. System.out.println("\nCliente n° " + (i + 1));
  448. client[i] = recordClient(key);
  449. }
  450. System.out.println("Registrazione avvenuta con successo.");
  451. System.out.println("\nQuanti dottori si vogliono registrare?");
  452. num = key.nextByte();
  453. bugfix = key.nextLine();
  454. Doctor[] doctor = new Doctor[num];
  455. System.out.println("Registrazione dottori in corso...");
  456. for (byte i = 0; i < num; ++i) {
  457. System.out.println("\nDottore n° " + (i + 1));
  458. doctor[i] = recordDoctor(key);
  459. }
  460. System.out.println("Registrazione avvenuta con successo.");
  461. System.out.println("\nQuante fatture si vogliono registrare?");
  462. num = key.nextByte();
  463. bugfix = key.nextLine();
  464. Invoice[] invoice = new Invoice[num];
  465. System.out.println("Registrazione fatture in corso...");
  466. for (byte i = 0; i < num; ++i) {
  467. System.out.println("\nFattura n° " + (i + 1));
  468. invoice[i] = recordInvoice(key, client, doctor);
  469. }
  470. System.out.println("Registrazione avvenuta con successo.");
  471. System.out.println("\nMENU\nScegli un'opzione:");
  472. System.out.println("1. VISUALIZZA STORICO FATTURE");
  473. System.out.println("2. VISUALIZZA FATTURE CON RICERCA DATA");
  474. prompt = key.nextByte();
  475. if (prompt == 1) showAllInvoices(invoice);
  476. else showInvoicesDate(invoice, key);
  477. System.out.println("Fine programma.");
  478. }
  479. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement