Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Week3/Counting Website Visits Quizz.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

1. Question 1
Run the method mostNumberVisitsByIP after a HashMap has been created from the method countVisitsPerIP on the file weblog1_log.

What number is returned?

133

2. Question 2
Run the method iPsMostVisits after a HashMap has been created from the method countVisitsPerIP on the file weblog1_log.

What single IP address is returned in the ArrayList?

84.190.182.222

3. Question 3
Run the method dayWithMostIPVisits with a HashMap has been created from the method iPsForDays on the file weblog1_log.

What day is returned?

4. Question 4
Run the method iPsWithMostVisitsOnDay with two parameters—one, a HashMap that has been created from the method iPsForDays on the file weblog1_log and two, the day “Mar 17”.

One IP Address is returned in the ArrayList—what is it?

200.129.163.70

137 changes: 137 additions & 0 deletions Week3/Web Logs server quizz. txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@

1. Question 1
Suppose a web log is modified to now have a sixth piece of information, a priority, that can be represented as a String.

Which one of the following is the least likely change to the LogEntry class to accommodate this new part of a web log?

A new String parameter is added to the constructor.

A new private variable named priority is created.

A new String field is initialized in the constructor.

A new getPriority method is created to return the priority.

The toString method is modified to include a String parameter.

The toString method is modified to include the new priority as part of the return String.

2. Question 2

Consider the following code for the readFile method of the LogAnalyzer class.

public void readFile(String filename) {
FileResource fr = new FileResource(filename);
for (String line : fr.lines()) {
LogEntry le = WebLogParser.parseEntry(line);
}
}

In the Tester class, readFile is called with a correct filename, and then printAll is called, but nothing is printed.

Which one of the following is likely the best reason why?

In readFile, the log entries were not stored in records.

3. Question 3
Consider the following code for the method printAllHigherThanNum with one integer parameter num. This method should print all the logs that have a status code higher than num.

Which one of the following would be the best choice for suitable code for this method?


for (LogEntry le : records) {
if (le.getStatusCode() > num) {
System.out.println(le);
}
}


if (le.getStatusCode() > num) {
for (LogEntry le : records) {
if (le.getStatusCode() > num) {
System.out.println(le);
}
}
}


for (LogEntry le : records) {
if (le.getStatusCode() > num) {
System.out.println(le);
}
else {
System.out.println();
}
}


if (le.getStatusCode() > num) {
for (LogEntry le : records) {
System.out.println(le);
}
}


if (le.getStatusCode() > num) {
for (LogEntry le : records) {
System.out.println(le);
}
}
else {
System.out.println();
}

4. Question 4
Run the method countUniqueIPs on the file weblog2_log.

How many unique IP addresses are in the file?

45

5. Question 5
Run the method uniqueIPVisitsOnDay(“Sep 27”) on the file weblog2_log.
What size is the ArrayList that is returned?

8

6. Question 6
Run the method countUniqueIPsInRange(400,499) on the file weblog2_log.
What number is returned?

23

7. Question 7
Run the method mostNumberVisitsByIP after a HashMap has been created from the method countVisitsPerIP on the file weblog2_log.
What number is returned?

63

8. Question 8
Run the method iPsMostVisits after a HashMap has been created from the method countVisitsPerIP on the file weblog2_log.

What single IP address is returned in the ArrayList?

188.162.84.63

9. Question 9
Run the method dayWithMostIPVisits with a HashMap has been created from the method iPsForDays on the file weblog2_log.

What day is returned?

Sep 24

Sep 26

Sep 28

Sep 30

10. Question 10
Run the method iPsWithMostVisitsOnDay with two parameters—one, a HashMap that has been created from the method iPsForDays on the file weblog2_log and two, the day “Sep 29”.
One IP address is returned in the ArrayList—what is it?

212.128.74.248




Binary file not shown.
17 changes: 17 additions & 0 deletions Week3/Website Visits/WebLogProgram/CountTester.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#BlueJ class context
comment0.target=CountTester
comment1.params=
comment1.target=CountTester()
comment2.params=
comment2.target=java.util.HashMap\ testCounts()
comment3.params=
comment3.target=void\ testmostNumberVisitsByIP()
comment4.params=
comment4.target=void\ testiPsMostVisits()
comment5.params=
comment5.target=void\ testiPsForDays()
comment6.params=
comment6.target=void\ testdayWithMostIPVisits()
comment7.params=
comment7.target=void\ testiPsWithMostVisitsOnDay()
numComments=8
88 changes: 88 additions & 0 deletions Week3/Website Visits/WebLogProgram/CountTester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

/**
* Website Visits
* In this assignement you will continue to build on the LogEntry and LogAnalyser classes
* that you worked on inth last lesson.You will continue to use the method parseEntry from
* the WebLogParser class, and you should not modify this class.You will write several
* methods to solve problems about web logs.
* Write a description of CountTester here.
* @author (Aymar N.)
* @version (08.08.2019)
*/

import java.util.*;

public class CountTester {

private ArrayList<String> maximumIPs;
private ArrayList<String> mostAccessesDay;

public CountTester(){
maximumIPs = new ArrayList<String>();
mostAccessesDay = new ArrayList<String>();
}

public HashMap<String,Integer> testCounts() {
LogAnalyzer la = new LogAnalyzer();
la.readFile("weblog3-short_log");
HashMap<String,Integer> counts = la.countVisitsPerIP();
System.out.println(counts);
return counts;
}

public void testmostNumberVisitsByIP() {
LogAnalyzer le = new LogAnalyzer();
//le.readFile("weblog3-short_log");
//le.readFile("weblog1_log");
le.readFile("weblog2_log");
int max_value = le.mostNumberVisitsByIP(testCounts());
System.out.println("max value in the HashMap "+ max_value);
}

public void testiPsMostVisits() {
LogAnalyzer Sol = new LogAnalyzer();
//Sol.readFile("weblog3-short_log");
//Sol.readFile("weblog1_log");
Sol.readFile("weblog2_log");
HashMap<String,Integer> myCounts = Sol.countVisitsPerIP();
maximumIPs = Sol.iPsMostVisits(myCounts);
for (int k=0;k<maximumIPs.size();k++) {
System.out.println(" IP addresses that all have the maximum number of visits "+ maximumIPs.get(k));
}
}

public void testiPsForDays() {
LogAnalyzer LA = new LogAnalyzer();
LA.readFile("weblog3-short_log");
HashMap<String,ArrayList<String>> map_day_ipaddress = LA.iPsForDays();
for (String s: map_day_ipaddress.keySet()) {
System.out.println(s+" maps to"+"\t"+map_day_ipaddress.get(s));
}
}

public void testdayWithMostIPVisits() {
String dayMostIP;
LogAnalyzer LogA = new LogAnalyzer();
//LogA.readFile("weblog3-short_log");
//LogA.readFile("weblog1_log");
LogA.readFile("weblog2_log");
HashMap<String,ArrayList<String>> map_day_ipaddress = LogA.iPsForDays();
dayMostIP = LogA.dayWithMostIPVisits(map_day_ipaddress);
System.out.println("The day that has the most IP address"+ dayMostIP);
}

public void testiPsWithMostVisitsOnDay() {
LogAnalyzer myLog = new LogAnalyzer();
//myLog.readFile("weblog3-short_log");
//myLog.readFile("weblog1_log");
myLog.readFile("weblog2_log");
HashMap<String,ArrayList<String>> day_and_ipaddress = myLog.iPsForDays();
//mostAccessesDay = myLog.iPsWithMostVisitsOnDay(day_and_ipaddress,"Sep 30");
mostAccessesDay = myLog.iPsWithMostVisitsOnDay(day_and_ipaddress,"Sep 29");
for (int k=0;k<mostAccessesDay.size();k++) {
System.out.println(" IP addresses that all have the maximum number of visits on Sep 29 "
+ mostAccessesDay.get(k));
}
}

}
Binary file not shown.
31 changes: 31 additions & 0 deletions Week3/Website Visits/WebLogProgram/LogAnalyzer.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#BlueJ class context
comment0.target=LogAnalyzer
comment1.params=
comment1.target=LogAnalyzer()
comment10.params=
comment10.target=int\ findMax()
comment11.params=dayIPs
comment11.target=java.lang.String\ dayWithMostIPVisits(java.util.HashMap)
comment12.params=dayandIPs\ aDay
comment12.target=java.util.ArrayList\ iPsWithMostVisitsOnDay(java.util.HashMap,\ java.lang.String)
comment13.params=myCounts
comment13.target=int\ mostNumberVisitsByIP(java.util.HashMap)
comment14.params=
comment14.target=void\ printAll()
comment2.params=filename
comment2.target=void\ readFile(java.lang.String)
comment3.params=
comment3.target=int\ countUniqueIPs()
comment4.params=Num
comment4.target=void\ printAllHigherThanNum(int)
comment5.params=someday
comment5.target=java.util.ArrayList\ uniqueIPVisitsOnDay(java.lang.String)
comment6.params=low\ high
comment6.target=int\ countUniqueIPsInRange(int,\ int)
comment7.params=
comment7.target=java.util.HashMap\ countVisitsPerIP()
comment8.params=addressNumberTime
comment8.target=java.util.ArrayList\ iPsMostVisits(java.util.HashMap)
comment9.params=
comment9.target=java.util.HashMap\ iPsForDays()
numComments=15
Loading