Tworzenie dziennika z wydarzeniami dodanymi przez użytkownika - JAVA
Plik diaryApp.java jest naszym driverem czyli plikiem do sterowania programu. Ten plik należy uruchomić, aby program zadziałał. Wczytuje oraz zapisuje dane do pliku app.txt.
Dalsza czê¶æ: 1 2 3 4
Listing
import java.util.*;
import java.io.*;
/**
* @author Funkcje.net
* @version 22-11-2007
*/
public class DiaryApp
{
//deklaracja zmiennych
private Diary diary;
private Scanner scan;
Scanner in = new Scanner(System.in);
public DiaryApp()
{
System.out.println("**Program is running**");
scan = new Scanner(System.in);
//creating new diary
diary = new Diary();
diary.today2();
}
//wczytywanie pliku
public void load() throws IOException
{
Scanner in =new Scanner(System.in);
diary.today();
System.out.println("loading from the file");
System.out.println("Using file: app.txt \n");
//nazwa pliku to app.txt
Scanner infile = new Scanner(new InputStreamReader (new FileInputStream("app.txt")));
int num = infile.nextInt();
for (int i=0;i<num;i++)
{
int dA = infile.nextInt();
int mA = infile.nextInt();
int yA = infile.nextInt();
int t = infile.nextInt();
int t2 = infile.nextInt();
String s = infile.next();
String p = infile.next();
Appointment a = new Appointment(s, dA, mA, yA, t, t2, p);
diary.addAppointment(a);
}
infile.close();
diary.sort();
}
//zapisywanie
public void save() throws IOException
{
PrintWriter outfile = new PrintWriter(new OutputStreamWriter(new FileOutputStream("app.txt")));
outfile.println(diary.size());
outfile.println(diary.toString());
outfile.close();
}
//wyświetlanie menu (GUI programu)
public void runMenu() throws IOException
{
diary.update();
char ch;
do{
System.out.println("Type any letter below and press enter to confirm:");
System.out.println("Type 'A' to add new appointment");
System.out.println("Type 'R' to remove appointment");
System.out.println("Type 'F' to search appointment");
System.out.println("Type 'P' to print out list of appointments");
System.out.println("Type 'S' to save to a file");
System.out.println("Type 'Q' to quit the program");
System.out.println("Type here ");
Scanner in=new Scanner(System.in);
String choice=in.next();
ch=choice.charAt(0);
switch(ch) {
case 'A': case 'a':
System.out.println("************");
System.out.println("Type new appointment");
System.out.println("************");
Appointment a = new Appointment();
a.readKeyboard();
diary.addAppointment(a);
save();
diary.clear();
load();
diary.sort();
System.out.println("*****************");
System.out.println("Appointment was added");
System.out.println("*****************");
break;
case 'F': case 'f':
diary.findDate();
diary.sort();
System.out.println("\n");
break;
case 'P': case 'p':
System.out.println("*************");
System.out.println("List of appointments:");
System.out.println("*************");
diary.sort();
diary.printOut();
System.out.println("\n");
break;
case 'R': case 'r':
diary.remove2();
diary.sort();
break;
case 'S': case 's':
save();
System.out.println("File was successful saved \n");
break;
//zakończenie menu - klawisz q
case 'Q': case 'q':
System.out.println("******************");
System.out.println("Files updated!");
System.out.println("******************");
System.out.println("Program was closed");
System.out.println("******************");
System.out.println("Thank you");
System.out.println("*********");
diary.sort();
break;
default:
System.out.println("***********************************");
System.out.println("Error!, Type again accepted letter!");
System.out.println("***********************************");
}
}while ((ch!='Q')&(ch!='q'));
}
//główna funkcja do otwierania programu
public static void main(String args[]) throws IOException
{
DiaryApp demo = new DiaryApp();
demo.load();
demo.runMenu();
demo.save();
System.out.println("******Program is down********");
}
}
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