Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pkg;
- import pkg.Date;
- public class Human {
- private String name;
- private String gendre;
- private String add;
- private Date birth;
- public Human() {
- this.name = this.gendre = this.add = null;
- this.birth = new Date();
- }
- public Human(String newName, String newGendre, String newAdd, Date newBirth) {
- this.name = newName;
- this.gendre = newGendre;
- this.add = newAdd;
- this.birth = newBirth;
- }
- public void setValue(String newName, String newGendre, String newAdd, Date newBirth) {
- this.name = this.gendre = this.add = null;
- this.birth = newBirth;
- }
- public String getName() {
- return this.name;
- }
- public String getGendre() {
- return this.gendre;
- }
- public String getAdd() {
- return this.add;
- }
- public Date getBirth() {
- return this.birth;
- }
- public void printType() {
- System.out.println("Classe: Human");
- }
- }
- package pkg;
- import java.util.Scanner;
- public class Date {
- private byte day;
- private byte month;
- private int year;
- public Date() {
- this.day = this.month = 0;
- this.year = 0;
- }
- public Date(byte newDay, byte newMonth, int newYear) {
- this.day = newDay;
- this.month = newMonth;
- this.year = newYear;
- }
- public void setValue(byte newDay, byte newMonth, int newYear) {
- this.day = newDay;
- this.month = newMonth;
- this.year = newYear;
- System.out.println("Modifica valori data avvenuta con successo.");
- }
- public boolean equals(Date otherDate) {
- if (this.year == otherDate.year) {
- if (this.month == otherDate.month) {
- if (this.day == otherDate.day) {
- return true;
- }
- }
- }
- return false;
- }
- public byte getDay() {
- return this.day;
- }
- public byte getMonth() {
- return this.month;
- }
- public int getYear() {
- return this.year;
- }
- }
- package pkg;
- import pkg.Human;
- import pkg.Date;
- public class ClientP extends Human {
- private String id;
- public ClientP() {
- super();
- this.id = null;
- }
- public ClientP(String newName, String newGendre, String newAdd, Date newBirth, String newId) {
- super(newName, newGendre, newAdd, newBirth);
- this.id = newId;
- }
- public void setValue(String newName, String newGendre, String newAdd, Date newBirth, String newId) {
- super.setValue(newName, newGendre, newAdd, newBirth);
- this.id = newId;
- }
- public String getName() {
- return super.getName();
- }
- public String getGendre() {
- return super.getGendre();
- }
- public String getAdd() {
- return super.getAdd();
- }
- public Date getBirth() {
- return super.getBirth();
- }
- public String getId() {
- return this.id;
- }
- public void printType() {
- System.out.println("Classe: ClientP");
- }
- }
- package pkg;
- import pkg.ClientP;
- public class Doctor extends ClientP {
- private String spec;
- public Doctor() {
- super();
- this.spec = null;
- }
- public Doctor(String newName, String newGendre, String newAdd, Date newBirth,
- String newId, String newSpec) {
- super(newName, newGendre, newAdd, newBirth, newId);
- this.spec = newSpec;
- }
- public void setValue(String newName, String newGendre, String newAdd, Date newBirth,
- String newId, String newSpec) {
- super.setValue(newName, newGendre, newAdd, newBirth, newId);
- this.spec = newSpec;
- }
- public String getName() {
- return super.getName();
- }
- public String getGendre() {
- return super.getGendre();
- }
- public String getAdd() {
- return super.getAdd();
- }
- public Date getBirth() {
- return super.getBirth();
- }
- public String getId() {
- return super.getId();
- }
- public String getSpec() {
- return this.spec;
- }
- }
- package pkg;
- import pkg.Date;
- import pkg.ClientP;
- import pkg.Doctor;
- public class Invoice {
- private Date dateReg;
- private int number;
- private Doctor nameDoctor;
- private ClientP nameClient;
- private String desc;
- private int amount;
- private int vat;
- public Invoice() {
- this.dateReg = new Date();
- this.number = 0;
- this.nameDoctor = new Doctor();
- this.nameClient = new ClientP();
- this.desc = null;
- this.amount = 0;
- this.vat = 0;
- }
- public Invoice(Date newDate, int newNumber, Doctor newDoctor,
- ClientP newClient, String newDesc, int newAmount, int newVat) {
- this.dateReg = newDate;
- this.number = newNumber;
- this.nameDoctor = newDoctor;
- this.nameClient = newClient;
- this.desc = newDesc;
- this.amount = newAmount;
- this.vat = newVat;
- }
- public void setValue(Date newDate, int newNumber, Doctor newDoctor,
- ClientP newClient, String newDesc, int newAmount, int newVat) {
- this.dateReg = newDate;
- this.number = newNumber;
- this.nameDoctor = newDoctor;
- this.nameClient = newClient;
- this.desc = newDesc;
- this.amount = newAmount;
- this.vat = newVat;
- }
- public Date getDate() {
- return this.dateReg;
- }
- public int getNumber() {
- return this.number;
- }
- public Doctor getDoctor() {
- return this.nameDoctor;
- }
- public ClientP getClient() {
- return this.nameClient;
- }
- public String getDesc() {
- return this.desc;
- }
- public int getAmount() {
- return this.amount;
- }
- public int getVat() {
- return this.vat;
- }
- }
- import pkg.Date;
- import pkg.ClientP;
- import pkg.Doctor;
- import pkg.Invoice;
- import java.util.Scanner;
- public class Main {
- private static ClientP recordClient(Scanner key) {
- String newName, newGendre, newAdd, newId;
- byte day, month;
- int year;
- Date newBirth;
- ClientP newClient;
- System.out.println("Inserire nome paziente:");
- newName = key.nextLine();
- System.out.println("Inserire genere paziente:");
- newGendre = key.nextLine();
- System.out.println("Inserire residenza:");
- newAdd = key.nextLine();
- System.out.println("Inserire giorno/mese/anno senza (GG MM AAAA) data di nascita:");
- day = key.nextByte();
- month = key.nextByte();
- year = key.nextInt();
- newBirth = new Date(day, month, year);
- System.out.println("Inserire ID paziente:");
- newId = key.nextLine();
- newId = key.nextLine();
- newClient = new ClientP(newName, newGendre, newAdd, newBirth, newId);
- return newClient;
- }
- private static Doctor recordDoctor(Scanner key) {
- String newName, newGendre, newAdd, newId, newSpec;
- byte day, month;
- int year;
- Date newBirth;
- Doctor newDoctor;
- System.out.println("Inserire nome dottore:");
- newName = key.nextLine();
- System.out.println("Inserire genere dottore:");
- newGendre = key.nextLine();
- System.out.println("Inserire residenza:");
- newAdd = key.nextLine();
- System.out.println("Inserire giorno/mese/anno senza (GG MM AAAA) data di nascita:");
- day = key.nextByte();
- month = key.nextByte();
- year = key.nextInt();
- newBirth = new Date(day, month, year);
- System.out.println("Inserire ID dottore:");
- newId = key.nextLine();
- newId = key.nextLine();
- System.out.println("Inserire specializzazione:");
- newSpec = key.nextLine();
- newDoctor = new Doctor(newName, newGendre, newAdd, newBirth, newId, newSpec);
- return newDoctor;
- }
- private static Doctor findDoctor(String newNameDoctor, Doctor[] doctor) {
- for (byte i = 0; i < doctor.length; ++i) {
- if (newNameDoctor.equalsIgnoreCase(doctor[i].getName()))
- return doctor[i];
- }
- return null;
- }
- private static ClientP findClient(String newNameClient, ClientP[] client) {
- for (byte i = 0; i < client.length; ++i) {
- if (newNameClient.equalsIgnoreCase(client[i].getName()))
- return client[i];
- }
- return null;
- }
- private static Invoice recordInvoice(Scanner key, ClientP[] client, Doctor[] doctor) {
- String newDesc, newNameDoctor, newNameClient;
- byte day, month;
- Date newDate;
- int year, newNumber, newAmount, newVat;
- Doctor newDoctor, resultD;
- ClientP newClient, resultC;
- Invoice newInvoice;
- System.out.println("Inserire giorno, mese e anno registrazione fattura" +
- " (GG/MM/AAAA):");
- day = key.nextByte();
- month = key.nextByte();
- year = key.nextInt();
- newDate = new Date(day, month, year);
- System.out.println("Inserire numero progressivo fattura:");
- newNumber = key.nextInt();
- System.out.println("Inserire nome dottore:");
- newNameDoctor = key.nextLine();
- newNameDoctor = key.nextLine();
- resultD = findDoctor(newNameDoctor, doctor);
- if (resultD == null) {
- System.out.println("Questo dottore non è registrato nel database.");
- return null;
- }
- newDoctor = resultD;
- System.out.println("Inserire nome paziente:");
- newNameClient = key.nextLine();
- resultC = findClient(newNameClient, client);
- if (resultC == null) {
- System.out.println("Questo paziente non è registrato nel database.");
- return null;
- }
- newClient = resultC;
- System.out.println("Inserire descrizione fattura:");
- newDesc = key.nextLine();
- System.out.println("Inserire totale fattura:");
- newAmount = key.nextInt();
- System.out.println("Inserire IVA:");
- newVat = key.nextInt();
- newInvoice = new Invoice(newDate, newNumber, newDoctor, newClient,
- newDesc, newAmount, newVat);
- return newInvoice;
- }
- private static void printInvoice(Invoice invoice) {
- Date date;
- date = invoice.getDate();
- System.out.print(date.getDay() + " " + date.getMonth() + " " +
- date.getYear() + "\t");
- System.out.println(invoice.getNumber() + "\t" + invoice.getDoctor().getName() +
- "\t" + invoice.getClient().getName() + "\t" + invoice.getAmount());
- }
- private static void showAllInvoices(Invoice[] invoice) {
- System.out.println("STORICO FATTURE:");
- for (byte i = 0; i < invoice.length; ++i) {
- printInvoice(invoice[i]);
- }
- }
- private static void showInvoicesDate(Invoice[] invoice, Scanner key) {
- System.out.println("Inserire data per cercare fatture: (GG/MM/AAAA)");
- Date date;
- byte day, month;
- int year;
- boolean flag = false;
- day = key.nextByte();
- month = key.nextByte();
- year = key.nextInt();
- date = new Date(day, month, year);
- for (byte i = 0; i < invoice.length; ++i) {
- if (invoice[i].getDate().equals(date))
- printInvoice(invoice[i]);
- flag = true;
- }
- if (!flag)
- System.out.println("Non è stata registrata nessuna fattura nel" +
- " giorno " + day + " " + month + " " + year + ".");
- }
- public static void main(String[] args) {
- System.out.println("Avvio programma");
- Scanner key = new Scanner(System.in);
- String bugfix;
- byte num, prompt;
- System.out.println("Quanti clienti si vogliono registrare?");
- num = key.nextByte();
- bugfix = key.nextLine();
- ClientP[] client = new ClientP[num];
- System.out.println("Registrazione pazienti in corso...");
- for (byte i = 0; i < num; ++i) {
- System.out.println("\nCliente n° " + (i + 1));
- client[i] = recordClient(key);
- }
- System.out.println("Registrazione avvenuta con successo.");
- System.out.println("\nQuanti dottori si vogliono registrare?");
- num = key.nextByte();
- bugfix = key.nextLine();
- Doctor[] doctor = new Doctor[num];
- System.out.println("Registrazione dottori in corso...");
- for (byte i = 0; i < num; ++i) {
- System.out.println("\nDottore n° " + (i + 1));
- doctor[i] = recordDoctor(key);
- }
- System.out.println("Registrazione avvenuta con successo.");
- System.out.println("\nQuante fatture si vogliono registrare?");
- num = key.nextByte();
- bugfix = key.nextLine();
- Invoice[] invoice = new Invoice[num];
- System.out.println("Registrazione fatture in corso...");
- for (byte i = 0; i < num; ++i) {
- System.out.println("\nFattura n° " + (i + 1));
- invoice[i] = recordInvoice(key, client, doctor);
- }
- System.out.println("Registrazione avvenuta con successo.");
- System.out.println("\nMENU\nScegli un'opzione:");
- System.out.println("1. VISUALIZZA STORICO FATTURE");
- System.out.println("2. VISUALIZZA FATTURE CON RICERCA DATA");
- prompt = key.nextByte();
- if (prompt == 1) showAllInvoices(invoice);
- else showInvoicesDate(invoice, key);
- System.out.println("Fine programma.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement