Question
*-------URGENT-------* *An Easy Assignment.* *This is for CS 102 Java class.* * I cannot use switch, conditional operator, break, continue, label, system.exit or exceptions, recursion.
*-------URGENT-------*
*An Easy Assignment.*
*This is for CS 102 Java class.*
* I cannot use switch, conditional operator, break, continue, label, system.exit or exceptions, recursion. *
Here is the link to the page:
http://www.cs.bilkent.edu.tr/~adayanik/courses/cs102/assignments/lab02/
I have the part a and b here:
a) SimpleURLReaderTest.java is test program to test the given two methods. It will log the content and count in consol
SimpleURLReaderTest.java-----------------------------------------------------------------------------------------
package lab02;
import cs1.SimpleURLReader;
public class SimpleURLReaderTest {
public static void main(String[] args) {
String url = "http://www.cs.bilkent.edu.tr/~david/housman.txt";
SimpleURLReader simpleURLReader = new SimpleURLReader(url);
System.out.println("Content:");
System.err.println(simpleURLReader.getPageContents());
System.out.println("Number of lines:");
System.out.println(simpleURLReader.getLineCount());
}
}
impleURLReaderTest.java-----------------------------------------------------------------------------------------
b) New class MySimpleURLReader created by extending SimpleURLReader so that you can re-use the methods from SimpleURLReader. Additional two method getURL() and getName() are added. getPageContents() method was overridden to check and remove "null". To test the class one more java class MySimpleURLReaderTest.java was created which you can find at the end.
MySimpleURLReader.java--------------------------------------------------------------------------------------------
package lab02;
import cs1.SimpleURLReader;
public class MySimpleURLReader extends SimpleURLReader{
String url;
public MySimpleURLReader(String url) {
super(url); //calling the super class constructor to set the url
this.url = url;
}
public String getURL(){
return url;
}
public String getName(){
return url.substring(url.lastIndexOf("/")+1); //lastIndexOf function give last index of a character in a string
}
@Override
public String getPageContents(){
String content = super.getPageContents(); //calling the super class getPageContents method and removing the first 4 characters
if(content.startsWith("null")); //checking if the content is starting with null
content = content.substring(4); //if yes, removing the first 4 characters
return content;
}
}
MySimpleURLReader.java--------------------------------------------------------------------------------------------
MySimpleURLReaderTest.java--------------------------------------------------------------------------------------
package lab02;
public class MySimpleURLReaderTest {
public static void main(String[] args) {
String url = "http://www.cs.bilkent.edu.tr/~david/housman.txt";
MySimpleURLReader mySimpleURLReader = new MySimpleURLReader(url);
System.out.println("Content:");
System.err.println(mySimpleURLReader.getPageContents());
System.out.println("Number of lines:");
System.out.println(mySimpleURLReader.getLineCount());
System.out.println("URL:");
System.out.println(mySimpleURLReader.getURL());
System.out.println("File Name:");
System.out.println(mySimpleURLReader.getName());
}
}
MySimpleURLReaderTest.java--------------------------------------------------------------------------------------
CS102 Lab02Reuse in OOP! Fall 2018 Introduction This assignment is designed to give you experience with reuse in Java, by employing inheritance to extend and modify the behaviour of Java classes. You will use the SimpleURLReader class from our cs1 package To complete the assignment, you do not need to know how the SimpleURLReader class works, you just treat it like any other Java class. One of the key points of this lab is to demonstrate that you can add to and modify the behaviour of an existing class, even without having its source code. Now that is neat! Setup Create your lab02 project from the CS101 console template, as usual, then download this cslpackage (right click and save it) to any convenient location outside of your lab02 project folder (e.g. the privatelcs102 folder that contains all your labXX folders.) You now need to add the package to your project's classpath so Java can find and use it. To do this in DrJava: Choose Project ProjectProperties then, in the "Extra Classpath" option, select "Add" and navigate to the cs1.jar file you just downloaded. Select it and click OK everywhere to complete the process. All being well you should now be able to import cs1.SimpleURLReader; into your classes Aside: You might be tempted to do this assignment without making use of (DrJava) projects -by setting the classpath in your computer's global environment settings or from the Edit Properties, ExtraClassPath option in DrJava~ but do not do so. Instead, use projects to organise your work. This is a key software engineering skill that will make your life much easier in the future, so make sure you learn how to do it now! CS102 Lab02Reuse in OOP! Fall 2018 Introduction This assignment is designed to give you experience with reuse in Java, by employing inheritance to extend and modify the behaviour of Java classes. You will use the SimpleURLReader class from our cs1 package To complete the assignment, you do not need to know how the SimpleURLReader class works, you just treat it like any other Java class. One of the key points of this lab is to demonstrate that you can add to and modify the behaviour of an existing class, even without having its source code. Now that is neat! Setup Create your lab02 project from the CS101 console template, as usual, then download this cslpackage (right click and save it) to any convenient location outside of your lab02 project folder (e.g. the privatelcs102 folder that contains all your labXX folders.) You now need to add the package to your project's classpath so Java can find and use it. To do this in DrJava: Choose Project ProjectProperties then, in the "Extra Classpath" option, select "Add" and navigate to the cs1.jar file you just downloaded. Select it and click OK everywhere to complete the process. All being well you should now be able to import cs1.SimpleURLReader; into your classes Aside: You might be tempted to do this assignment without making use of (DrJava) projects -by setting the classpath in your computer's global environment settings or from the Edit Properties, ExtraClassPath option in DrJava~ but do not do so. Instead, use projects to organise your work. This is a key software engineering skill that will make your life much easier in the future, so make sure you learn how to do it nowStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started