Tworzenie dziennika z wydarzeniami dodanymi przez użytkownika - JAVA
Plik appointment.java wyświetla wydarzenie w odpowiedniej formie oraz jest odpowiedzialny za każdy wpis do dziennika (dla obiektów tej klasy).
Listing
import java.util.*;
/**
* @author Funkcje.net
* @version 22-11-2007
*/
public class Appointment
{
//deklarowanie zmiennych
private String subject;
private int dayApp;
private int monthApp;
private int yearApp;
private int timeStart;
private int timeEnd;
private String person;
private int date;
public Appointment()
{
subject = "unknown";
dayApp = 00;
monthApp = 00;
yearApp = 0000;
timeStart = 0000;
timeEnd = 0000;
person = "unknown";
date = dayApp+100*monthApp+10000*yearApp;
}
public Appointment(String s, int dA, int mA, int yA, int t, int t2, String p) {
subject = s;
dayApp = dA;
monthApp = mA;
yearApp = yA;
timeStart = t;
timeEnd = t2;
person = p;
//generowanie formatu daty
date = dayApp+100*monthApp+10000*yearApp;
}
//dodawanie wydarzenia
public void readKeyboard() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the subject for appoinment: ");
subject=in.next();
System.out.println("Enter person with who you have got appointment: ");
person=in.next();
System.out.println("Enter the day of appointment (dd): ");
dayApp=in.nextInt();
if (dayApp<=0 || dayApp>=32) {
do{
System.out.println("Error");
System.out.println("Please type number from 01 - 31");
dayApp=in.nextInt();
}while (dayApp<0 && dayApp<32);
}
System.out.println("Enter the month of appointment (mm): ");
monthApp=in.nextInt();
//here is the same situation but for the numbers 1-12
if (monthApp<=0 || monthApp>=13) {
do{
System.out.println("Error");
System.out.println("Please type number from 01 - 12");
monthApp=in.nextInt();
}while (monthApp<0 && monthApp>13);
}
System.out.println("Enter the year of appointment (yyyy): ");
yearApp=in.nextInt();
System.out.println("Enter starting time (for example: 1254): ");
timeStart=in.nextInt();
System.out.println("Enter ending time (for example: 1354): ");
timeEnd=in.nextInt();
System.out.println("***********************");
System.out.println("I'm writing into a file");
System.out.println("***********************");
//printed actual added informations
this.printOut();
}
//format daty
public void date()
{
System.out.println("Date: "+dayApp+"/"+monthApp+"/"+yearApp);
}
//wyświetlanie
public void printOut() {
System.out.println("Subject of Appointment: " + subject);
System.out.println("Appointment with: " + person);
date();
System.out.println("Start time: " + timeStart);
System.out.println("Ends time: " + timeEnd);
}
public void setSubject(String s) {
subject = s;
}
public String getSubject()
{
return subject;
}
public void setDate(int d) {
date = d;
}
public int getDate() {
return date;
}
public void setTime(int t) {
timeStart = t;
}
public int getTime() {
return timeStart;
}
public boolean equals(Appointment other)
{
if((this.subject).equals (other.subject))
return true;
else
return false;
}
//tworznie wyświetlania pojedynczego wydarzenia
public void print2()
{
System.out.println("- DATE "+dayApp+"/"+monthApp+"/"+yearApp+", Start: "+timeStart+", End: "+timeEnd+", Subject: "+subject+", With: "+person);
}
public String toString() {
return ""+dayApp+" "+monthApp+" "+yearApp+" "+timeStart+" "+timeEnd+" "+subject+" "+person;
}
}
Dodano przez: divix
Ranga: Administrator serwisu Punktów: 0
Ranga: Administrator serwisu Punktów: 0
Komentarze użytkowników
:: Losowe artykuły
:: Wymiana linków
Modowe inspiracje |
Android Gry i Aplikacje |
ZaplanujTransport.pl: Przeprowadzki, transport, aukcje |
Logo dla firmy |
Change Tires - Car Weather Forecast Reminder |
Laminas: MVC Framework for PHP |
IT Books Reviews and Programming: JS, JAVA, PHP, ANDROID, CSS |
Katalog roślin |
Programming articles: JAVA, PHP, C++, Python, JavaScript |
Kancelaria Adwokacka Łukasz Huszno