Q:

linkedlist project for cs210 course

1

Tourism development is an important driver of growth for the future of Saudi Arabia. It is one of the key pillars at the heart of Vision 2030’s plan to help diversify the economy and reduce reliance on oil.

 

The Saudi Tourism Authority is the official promoter of Visit Saudi. The Authority was established to support the growth of the travel and tourism sector. It developed VisitSaudi.com for information on Saudi Arabia’s diverse and fascinating tourism offer. You can easily discover events all around the kingdom from the Saudi Calendar.

 

Assuming that you are working on the back-end of this website, you will write a java program to store events’ data and process various requests. Your Java program should do the following:

 

  1. Read the data from a text file and store it in a linked list (2 points)
  2. Print all events around the kingdom (1 point)
  3. Filter events by Date, City, Category, Audience or Fees (3 points)
  4. Add, Remove or Edit an event (3 points)
  5. Search for an event by name fully or partially (1 point)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Event.java:

package pro;

import java.util.LinkedList;

class Event {
  public String Title;
  public String About;
  public String Date;
  public String City;
  public String Category;
  public String Audience;
  public String Fees;

  Event(String n, String s, String c, String st, String cd, String au, String fe) {
	  Title = n;
	  About = s;
	  Date = c;
	  City = st;
	  Category = cd;
	  Audience = au;
	  Fees = fe;
  }

  public String toString() {
    return Title + "\n" + About + "\n" + Date + "\n" + City + "\n" + Category+ "\n" + Audience+ "\n" + Fees + "\n";
  }
}

 

MainApp.java:

package pro;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/*
 * Java Program read a text file into ArrayList in Java 6
 * and Java 8. 
 */

public class MainApp {
	
//	this function for filter events by Date
	public static LinkedList<Event> filterItem(LinkedList<Event> l) {

        LinkedList<Event> toReturn = new LinkedList<Event>();
        for (Event myObj : l) {
//        	Return the list containing this date
            if (myObj.Date.contains("29 September 2022 - 16 October 2022")) {
            	
                toReturn.add(myObj);
            }
            
            
//          for  Return the list that does not contain this date
//			if (myObj.Date.contains("29 September 2022 - 16 October 2022")) {
//            	
//                toReturn.add(myObj);
//            }
        }
        return toReturn;
    }


  public static void main(String[] args) throws Exception {

   
    BufferedReader bufReader = new BufferedReader(new FileReader("PRO.txt"));

    LinkedList<Event> listOfLines = new LinkedList<Event>();
    String line = bufReader.readLine();
  String Title = null;
   String About = null;
     String Date = null;
  String City = null;
 String Category = null;
    String Audience = null;
   String Fees = null;

    while (line != null) {

    		 
    
      if(line.contains("Event ")){
    	  Title = line;

      } else if (line.contains("About")){

    	   About = line;
      }else if (line.contains("Date")){
    	   Date = line;
      }else if (line.contains("City")){
    	   City = line;
      }else if (line.contains("Category")){
    	   Category = line;
      }else if (line.contains("Audience")){
    	   Audience = line;
      }else if (line.contains("Fees")){
    	   Fees = line;
      }
      
      
      if(Title != null & About != null & Date != null & City != null & Category != null & Audience != null & Fees != null){
      listOfLines.add(new Event(Title, About, Date, City, Category,Audience, Fees));
      Title = null;

       About = null;

         Date = null;

     City = null;

    Category = null;
       
        Audience = null;
       
       Fees = null;
      }
      line = bufReader.readLine();
    }

    bufReader.close();

//  2:  for print linked list
    for (Event element : listOfLines)
	      System.out.println(element + "\n");
    
//   4: for add an event to linked list 
    listOfLines.add(new Event("Event 8: Private libraries", "About: The individual libraries aim to collect the most prominent and important books owned by the most famous Saudi and Arab intellectuals and create a different experience for visitors to the exhibition by reviewing the most important scripts and old publications. It will also include a number of King Faisal’s books,May Allah Bless his Soul, in addition to various writers and intellectuals.", "Date: 29 Sep 2022 - 08 Oct 2022", "City: Riyadh", "Category: Convention & Exhibition","Audience: All", "Fees: Paid Event"));
//    remove event
    listOfLines.removeFirst();
//    listOfLines.removeLast();
    
    for (Event element : listOfLines)
	      System.out.println(element + "\n");
    
//    5:search
    for (Event s : listOfLines){
    if (s.Title.contains("Private libraries")) {
        System.out.println("LinkedList contains an event");
      } else {
        System.out.println("LinkedList does not contain an event");
      }
    } 
    
//  3:  filter by Date
    System.out.println(filterItem(listOfLines));
  }
}

 

Screenshots

question2-1:

 

question 2-2:

question 3:

question 4-1:

question 4-2:

question 5:

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now