So I have finally completed my program, and now need to output the array to a text file and then have the ability to save it, and then load that file. So far I have started the on the saving, but I can seem to get it to create the file.
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class Test {
/**
* @author Alexander Chamerlaion
* @Version 1.0
* @Date 10/12/11
* This program creates and tests Social Events
*/
static String title, attire, dayweek,input,time;
static int day,month,year;
public static void main(String[] args) {
SocialEventList sel = new SocialEventList();
Scanner k = new Scanner(System.in);
for(int i = 0; i<1000;++i){
System.out.println("Please enter what you would like to add/execute/quit \n(Party, Club Meeting, Dance Class,Date Check,Display,Save,Load,Quit)");
String input = k.nextLine();
input=input.toUpperCase();
if(input.equals("PARTY")){
System.out.println("Choosen a Party");
System.out.println("Please enter a description of your event: ");
title=k.next();
System.out.println("Please Enter an attire: ");
attire = k.next();
System.out.println("Please Enter an time: ");
time=k.next();
System.out.println("Please enter the date input the day first: ");
day=k.nextInt();
System.out.println("Month: ");
month=k.nextInt();
System.out.println("Year: ");
year=k.nextInt();
System.out.println("Please enter the day it occurs on(Monday,Tuesday,etc): ");
dayweek=k.next();
Party p = new Party(attire, dayweek, title, day, month, year,time);
p.setPartyTime(time);
p.setPartyTitle(title);
p.setPartyAttire(attire);
p.setPartyMonth(month);
p.setPartyYear(year);
p.setPartyDay(day);
p.setPartyDayweek(dayweek);
sel.add(p);
sel.display();
}
else if (input.equals("DANCE CLASS")){
System.out.println("Choosen a Dance Class");
System.out.println("Please enter a description of your event: ");
title=k.next();
System.out.println("Please Enter an attire: ");
attire = k.next();
System.out.println("Please Enter an time: ");
time=k.next();
System.out.println("Please enter the date input the day first: ");
day=k.nextInt();
System.out.println("Month: ");
month=k.nextInt();
System.out.println("Year: ");
year=k.nextInt();
System.out.println("Please enter the day it occurs on(Monday,Tuesday,etc): ");
dayweek=k.next();
DanceClass d = new DanceClass(attire, title, time, day, month, year, dayweek);
d.setDanceTitle(title);
d.setDanceAttire(attire);
d.setDanceTime(time);
d.setDanceDay(day);
d.setDanceMonth(month);
d.setDanceYear(year);
d.setDanceDayweek(dayweek);
sel.add(d);
sel.display();
}
else if(input.equals("CLUB MEETING")){
System.out.println("You've Choosen A Club Meeting ");
System.out.println("Please enter a description of your event: ");
title=k.next();
System.out.println("Please Enter an attire: ");
attire = k.next();
System.out.println("Please Enter an time: ");
time=k.next();
System.out.println("Please enter the date input the day first: ");
day=k.nextInt();
System.out.println("Month: ");
month=k.nextInt();
System.out.println("Year: ");
year=k.nextInt();
System.out.println("Please enter the day it occurs on(Monday,Tuesday,etc): ");
dayweek=k.next();
ClubMeeting c = new ClubMeeting(attire, title, time, day, month, year, dayweek);
c.setClubTitle(title);
c.setClubAttire(attire);
c.setClubTime(time);
c.setClubDay(day);
c.setClubMonth(month);
c.setClubYear(year);
c.setClubDayweek(dayweek);
sel.add(c);
sel.display();
}
else if(input.equals("DISPLAY")){
sel.display();
}
else if(input.equals("DATE CHECK")){
System.out.println("Please enter a date to be checked");
System.out.println("Please enter the day: ");
day=k.nextInt();
System.out.println("Please enter the month: ");
month=k.nextInt();
System.out.println("Please enter the year: ");
year=k.nextInt();
sel.occursOn(month,day,year);
}
else if(input.equals("SAVE")){
sel.saveAppointmentData();
}
else if(input.equals("QUIT")){
break;
}
}
}
}
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class SocialEventList {
private SocialEvent[] thelist = new SocialEvent[10];
private int i = 0;
private int counter = 0;
public void add(SocialEvent se){
if(i<thelist.length){
thelist[i]=se;
++i;
System.out.println(thelist[i]);
}
}
public void display(){
for(int j = 0; j < i; j++){
System.out.println(thelist[j].toString(i));
}
}
public void occursOn(int month, int day, int year) {
for(int h = 0; h<i;h++)
{
if( month==thelist[h].getMonth()&&day==thelist[h].getDay() &&year==thelist[h].getYear() ) {
System.out.println("You have event "+h+ " that occurs on the same day, check to make sure you have enough time.");
display();
}
else{
System.out.println("This event "+h+ " are no two events occur on this same day");
}
}
}
public void saveAppointmentData(){
PrintStream out = null;
try {
out = new PrintStream(new FileOutputStream(toString()));
out.println();
}
catch(FileNotFoundException e){
System.out.println("Error opening the file ");
System.exit(0);
}
}
}
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class SocialEvent {
private String title;
private String attire;
private String time;
private int day;
private int month;
private int year;
private String dayweek;
private String save;
public SocialEvent(String attire,String dayweek, String title,int day,int month,int year, String time){
this.attire = attire;
this.dayweek = dayweek;
this.title = title;
this.day = day;
this.month = month;
this.year = year;
this.time = time;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAttire() {
return attire;
}
public void setAttire(String attire) {
this.attire = attire;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getDayweek() {
return dayweek;
}
public void setDayweek(String dayweek) {
this.dayweek = dayweek;
}
public String toString(int i) {
return "\nTitle: "+title+"\nAttire: "+attire+"\nDate: "+month+"/"+day+"/"+year+"\nDay of the Week: "+
dayweek+"\nTime: "+time;
}
}
other 3 classes set up like this
public class Party extends SocialEvent {
public Party(String attire,String dayweek, String title,int day,int month,int year, String time){
super(attire, dayweek, title, day, month, year,time);
}
public void setPartyTime(String partyTime){
super.setTime(partyTime);
}
public String getPartyTime(){
return super.getTime();
}
public String getPartyAttire() {
return super.getAttire();
}
public void setPartyAttire(String partyAttire) {
super.setAttire(partyAttire);
}
public String getPartyTitle() {
return super.getTitle();
}
public void setPartyTitle(String partyTitle) {
super.setTitle(partyTitle);
}
public String getPartyDayweek() {
return super.getDayweek();
}
public void setPartyDayweek(String partyDayweek) {
super.setDayweek(partyDayweek);
}
public int getDay() {
return super.getDay();
}
public void setPartyDay(int partyDay) {
super.setDay(partyDay);
}
public int getMonth() {
return super.getMonth();
}
public void setPartyMonth(int partyMonth) {
super.setMonth(partyMonth);
}
public int getYear() {
return super.getYear();
}
public void setPartyYear(int partyYear) {
super.setYear(partyYear);
}
public String toString(int i){
return "Party" + super.toString(i);
}
}