Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I needed help with writing a code for this.... 3.1) Learning Objective: To declare, create, and initialize an ArrayList list. Instructions: See the instructions in

I needed help with writing a code for this....

3.1) Learning Objective: To declare, create, and initialize an ArrayList list. Instructions: See the instructions in 1.1 for what to submit for grading. This is not a complete program. Name your class H01_31 and save it in a fle named H01_31.java. When you are done, copy H01_31.java to your asuriteid-h01 folder, i.e., to the same folder as the PDF.

Problem: Write a public instance method named ArrayList arrayListInit() that creates an ArrayList object named list and flls list with the numbers shown below (using one or a pair of for or whiie loops, i.e., if you just call add() to add the numbers to list, your solution will be marked as incorrect). list shall be returned from arrayListInit(). Note that your method shall not output the contents of the list, just return it.

0 1 2 3 4 0 1 2 3 4

Testing: We will be testing your method using our driver routine. For testing on your end, write your own driver routine in a class diferent than H01_31.3.4) To compute a running sum of the elements of an ArrayList list.

Instructions: See the instructions in 1.1 for what to submit for grading. This is not a complete program. Name your class H01_34 and save it in a fle named H01_34.java. When you are done, copy H01_34.java to your asuriteid-h01 folder, i.e., to the same folder as the PDF.

Testing: We will be testing your method using our driver routine. For testing on your end, write your own driver routine in a class diferent than H01_34. Make sure to test the cases where list is empty and where the pList parameter is null.

3.4 )To compute a running sum of the elements of an ArrayList list.

Instructions: See the instructions in 1.1 for what to submit for grading. This is not a complete program. Name your class H01_34 and save it in a fle named H01_34.java. When you are done, copy H01_34.java to your asuriteid-h01 folder, i.e., to the same folder as the PDF.

Problem: See the instructions in 1.1 for what to submit for grading. This is not a complete program. Name your Java source code fle H01_34.java. Write a public instance method named Integer arrayListSum(ArrayList pList). The method shall return the sum of the elements of pList as an Integer. Note that the sum of an empty list is 0. If the pList reference variable is null, then return 0 as well.

Testing:For testing on your end, write your own driver routine in a class diferent than H01_34. Make sure to test the cases where list is empty and where the pList parameter is null.

3.5) To declare, create, and initialize an ArrayList list.

Problem: Write a public instance method named named ArrayList arrayListCreate(int pLen, int pInit Value). The method shall use a while or for loop to create a new ArrayList object which has exactly pLen elements, pLen 0. Each ele ment shall be initialized to pInitValue. The method shall return the ArrayList.

Testing: We will be testing your method using our driver routine. For testing on your end, write your own driver routine in a class diferent than H01_35. Make sure to test the case where pLen is 0.

4.3)Learning Objective: To read and write text fles.

Instructions: See the instructions in 1.2 for what to submit for grading. This is complete program with one Java source code fle named H01_43.java (your main class is named H01_43). When you are done, copy H01_43.java to your asuriteid-h01 folder, i.e., to the same folder as the PDF.

Problem: Write a program that prompts the user for the name of a Java source code fle (you may assume the fle contains Java source code and has a .java flename extension; we will not test your program on non-Java source code fles). The program shall read the source code fle and output the contents to a new fle named the same as the input fle, but with a .txt fle name extension, e.g., if the input fle is foo.java then the output fle shall be named foo.java.txt. Each line of the input fle shall be numbered with a line number (formatted as shown below) in the output fle. For example, if the user enters H01_43.java as the name of the input fle and H01_43.java contains: //*************************************************************** //

CLASS: H01_43

//***************************************************************

public class H01_43 {

public static void main(String[] pArgs) {

}

private run() {

}

}

5.3 Learning Objective: To demonstrate knowledge of checked and unchecked exceptions. Instructions: Include your answer in asuriteid-h01.pdf. Problem: Explain what an unchecked exception is. Give one example.

5.5)To demonstrate knowledge of exception handling.

Instructions: Include your answer in asuriteid-h01.pdf. Problem: Why dont you need to declare that your method might throw an IndexOutOfBoundsException?

5.6)To demonstrate knowledge of exception handling.

Instructions: Include your answer in asuriteid-h01.pdf.

Problem: Is the type of the exception object that gets thrown always the same as the exception type declared in the catch clause that catches the exception? If not, why not?

6.3)To demonstrate knowledge of instance and class methods.

Problem:

(a) In a static method, it is easy to diferentiate between calls to instance methods and calls to static methods. How do you tell the method calls apart?

(b) Why is it not as easy to distinguish between calls to instance and static methods which are called from an instance method?

6.4) To demonstrate knowledge of constructors, instantiating objects, and calling methods.

Problem:

Explain what happens when this application runs and why.

public class C {

private int x;

private String s;

public static void main(String[] pArgs) {

new C();

}

public C() {

x = s.length();

System.out.println("x = " + x);

}

}

6.8)To demonstrate knowledge of accessing the public/private data and methods of a class.

Problem: Continuing the previous exercise. Within main(), are the following statements syntactically legal, i.e., do they compile? If so, describe what happens when the statement is executed. If not, explain why the statement is syntactically illegal. You may write these statements in main() to solve this exercise, but do not include these statements in the Java fle you submit for grading.

(a) int a1 = H01_65.mX;

(b) int a2 = H01_65.mY;

(c) int a3 = H01_65.A;

(d) int a4 = H01_65.B;

(e) cObj1.H01_65(20);

(f) int a5 = cObj1.getX();

(g) cObj1.setX(20);

(h) cObj2.setX(cObj1.getX());

(i) int a6 = H01_65.getX();

(j) H01_65.setX(20);

(k) int a7 = cObj1.getY();

(l) cObj1.setY(20);

(m)int a8 = H01_65.getY();

(n) H01_65.setY(20);

7.2)To draw a UML class diagram with relationships. Instructions: Shown below is a UML class diagram which shows several classes that are associated in various way.

Problem:

(a) Note that in Course there is an instance variable mRoster which is an instance of Roster. When a Course object is deleted, the Roster instance mRoster will also be deleted. Given that, what type of class relationship, if any, exists between Course and Roster? If there is a relationship, modify the diagram to indicate the relationship and label each end of the relationship with a multiplicity.

(b) Note that in Roster there is an instance variable mStudents which is an ArrayList of Student objects. When a Roster object is deleted, mStudents is also deleted, but each Student object within mStudents is not deleted. Given that, what type of class relationship, if any, exists between Roster and Student. If there is a relationship, modify the diagram to indicate the relationship and label each end of the relationship with a multiplicity.

(c) What type of class relationship, if any, exists between Student and UndergradStudent? If there is a relationship, modify the diagram to indicate the relationship (note that we do not use multiplicities on superclass/subclass relationships).

(d) What type of class relationship, if any, exists between Student and GradStudent? If there is a relationship, modify the diagram to indicate the relationship. Should there be a multiplicity applied to this relationship? If you think so, then indicate it.

(e) What type of class relationship, if any, exists between UndergradStudent and GradStudent? If there is a relationship, modify the diagram to indicate the relationship.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions