Fixed Length format

 EVENT.JAVA:

public class Event {

String name, detail, type,organiser;

int attendeesCount;

double projectedExpense;

public Event(String name, String detail,String type,String organiser,int attendeesCount, double projectedExpense)

{

super();

this.name = name;

this.detail = detail;

this.type = type;

this.organiser = organiser;

this.attendeesCount = attendeesCount;

this.projectedExpense = projectedExpense;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;
}

public String getDetail() {

return detail;

}

public void setDetail(String detail) {

this.detail = detail;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public String getOrganiser() {

return organiser;

}

public void setOrganiser(String organiser) {

this.organiser = organiser;

}

public int getAttendeesCount() {

return attendeesCount;

}

public void setAttendeesCount(int attendeesCount) {

this.attendeesCount = attendeesCount;

}

public double getProjectedExpense() {

return projectedExpense;

}

public void setProjectedExpense(double projectedExpense) {

this.projectedExpense = projectedExpense;

}

@Override

public String toString()

{

return String.format("%-15s%-20s%-15s%-15s%-15s\n",this.getName(),this.getDetail(),this.type,this.attendeesCount,this.projectedExpense);

}

}



EVENTBO.JAVA:

import java.util.*;

import java.io.*;

public class EventBO {

public static ArrayList<Event> readFile(BufferedReader br) throws Exception {

ArrayList<Event> e = new ArrayList<Event>();

Event event;

String line;

while((line=br.readLine())!=null)

{

String name = line.substring(0,19).trim();

String detail = line.substring(19,39).trim();

String type = line.substring(39,51).trim();

String organiser = line.substring(51,61).trim();

String attendeesCount = line.substring(61,67).trim();

String projectedExpense = line.substring(67,74).trim();

event = new Event(name,detail,type,organiser,Integer.parseInt(attendeesCount),Double.parseDouble(projectedExpense));

e.add(event);

}

br.close();

return e;
}

public static ArrayList<Event> eventsByPerson(ArrayList<Event> eventList,String organiser) {

ArrayList<Event>e = new ArrayList<Event>();

for(int i =0; i<eventList.size();i++)

{

if(eventList.get(i).getOrganiser().equals(organiser))

{

e.add(eventList.get(i));

}

}

return e;

}

}
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		//write your code here
		 Scanner sc = new Scanner(System.in);
	        
	        try {
	            FileReader freader = new FileReader("input.csv");
	            BufferedReader br = new BufferedReader(freader);
	            ArrayList<Event> events = EventBO.readFile(br);
	            String choice = null;
	            String organizer = null;
	            ArrayList<Event> filter;
	            do {
	                System.out.println("Enter the name of the person whose events to be shown:");
	                organizer = sc.nextLine();
	                
//	                Print filter
	                filter = EventBO.eventsByPerson(events, organizer);
	                if (filter.size() > 0)
	                {
	                    System.out.printf("%-15s%-20s%-15s%-15s%-15s%-15s\n", "Name", "Detail", "Type", "Attendees", "CountProjected", "Expense");
	                    for (Event event:filter)
	                    {
	                        System.out.println(event);
	                    }
	                }
	                else
	                {
	                    System.out.println("The given person has no upcoming events");
	                }
//	                Check continue
	                System.out.println("Do you want to continue?(y/n)");
	                choice = sc.nextLine();
	            } while (choice.equals("y"));
	        } catch (FileNotFoundException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
	        catch (Exception e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
//	        System.out.printf("%.5s", "1");
	    }
		
	}




MAIN.JAVA:

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.