17.07.2015 Views

ECET 370 Week 1 Lab 1

General Instructions Exercises 1, 2, 4, and 5 use the programs in DocSharinglabeled “User-defined classes." Exercises 7 and 8 use the programs in DocSharinglabeled “Using interfaces." Exercise 1: Review of classes Create a project using the classes in the DocSharing area labeled “User-defined classes." Compile it, run it, and review the code that is given carefully. Exercise 2: User-defined methods The function area of the Triangle class is the framework of the actual method. Modify it so that it calculates the area of the triangle. Write a Main class to test your area method. Note: to calculate the area of a triangle from the vertices, first find the distances between each pair of vertices to obtain the length of the sides of the triangle. Then apply Heron’s formula to calculate the area given the length of the sides. Exercise 3: Shallow versus deep copy Provide an example of shallow copy of objects and an example of deep copy of objects. Exercise 4: Passing parameters to methods Write a function that swaps two Point objects. Use the code given below: import java.util.*; public class Main { public Main() { Scanner Scanner(System.in); System.out. print("Enter x and y coordinates of first point: "); Point Point (in.nextDouble(), in.nextDouble()); System.out. print("Enter x and y coordinates of second point: "); Point Point (in.nextDouble(), in.nextDouble()); swap(p1, p2); System.out.println(" Compile it, run it, and review the code that is given carefully. Note: The class Point implements the Comparable interface. The Comparable interface contains a single method: compareTo, which is used to compare two objects p and q of the same class type. When calling p.compareTo(q), it returns an integer. If this value is negative it means that p is smaller; if it is equal to zero then , and if the value is positive, it indicates that p is greater than q. Exercise 8: Implementation of interfaces Using the class Point in the DocSharing area labeled “Using interfaces," write an application that declares an array of Points, fills the array with random points, and finds the smallest point in the array.

General Instructions
Exercises 1, 2, 4, and 5 use the programs in DocSharinglabeled “User-defined classes."
Exercises 7 and 8 use the programs in DocSharinglabeled “Using interfaces."
Exercise 1: Review of classes Create a project using the classes in the DocSharing area labeled “User-defined classes." Compile it, run it, and review the code that is given carefully.
Exercise 2: User-defined methods The function area of the Triangle class is the framework of the actual method. Modify it so that it calculates the area of the triangle. Write a Main class to test your area method. Note: to calculate the area of a triangle from the vertices, first find the distances between each pair of vertices to obtain the length of the sides of the triangle. Then apply Heron’s formula to calculate the area given the length of the sides.
Exercise 3: Shallow versus deep copy Provide an example of shallow copy of objects and an example of deep copy of objects.
Exercise 4: Passing parameters to methods Write a function that swaps two Point objects. Use the code given below: import java.util.*; public class Main { public Main() { Scanner Scanner(System.in); System.out. print("Enter x and y coordinates of first point: "); Point Point (in.nextDouble(), in.nextDouble()); System.out. print("Enter x and y coordinates of second point: "); Point Point (in.nextDouble(), in.nextDouble()); swap(p1, p2); System.out.println(" Compile it, run it, and review the code that is given carefully. Note: The class Point implements the Comparable interface. The Comparable interface contains a single method: compareTo, which is used to compare two objects p and q of the same class type. When calling p.compareTo(q), it returns an integer. If this value is negative it means that p is smaller; if it is equal to zero then , and if the value is positive, it indicates that p is greater than q.
Exercise 8: Implementation of interfaces Using the class Point in the DocSharing area labeled “Using interfaces," write an application that declares an array of Points, fills the array with random points, and finds the smallest point in the array.

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ECET</strong> <strong>370</strong> <strong>Week</strong> 1 <strong>Lab</strong> 1<br />

Click Here to Buy the Tutorial<br />

http://www.uoptutorial.com/index.php?route=product/product&path=614&product<br />

_id=9327<br />

For more course tutorials visit<br />

www.uoptutorial.com<br />

General Instructions<br />

Exercises 1, 2, 4, and 5 use the programs in DocSharinglabeled “User-defined classes."<br />

Exercises 7 and 8 use the programs in DocSharinglabeled “Using interfaces."<br />

Exercise 1: Review of classes Create a project using the classes in the DocSharing area labeled<br />

“User-defined classes." Compile it, run it, and review the code that is given carefully.<br />

Exercise 2: User-defined methods The function area of the Triangle class is the framework of the<br />

actual method. Modify it so that it calculates the area of the triangle. Write a Main class to test<br />

your area method. Note: to calculate the area of a triangle from the vertices, first find the<br />

distances between each pair of vertices to obtain the length of the sides of the triangle. Then<br />

apply Heron’s formula to calculate the area given the length of the sides.<br />

Exercise 3: Shallow versus deep copy Provide an example of shallow copy of objects and an<br />

example of deep copy of objects.<br />

Exercise 4: Passing parameters to methods Write a function that swaps two Point objects. Use<br />

the code given below: import java.util.*; public class Main { public Main() { Scanner<br />

Scanner(System.in); System.out. print("Enter x and y coordinates of first point: "); Point Point<br />

(in.nextDouble(), in.nextDouble()); System.out. print("Enter x and y coordinates of second point:<br />

"); Point Point (in.nextDouble(), in.nextDouble()); swap(p1, p2); System.out.println(" Compile it,<br />

run it, and review the code that is given carefully. Note: The class Point implements the<br />

Comparable interface. The Comparable interface contains a single method: compareTo, which is<br />

used to compare two objects p and q of the same class type. When calling p.compareTo(q), it<br />

returns an integer. If this value is negative it means that p is smaller; if it is equal to zero then ,<br />

and if the value is positive, it indicates that p is greater than q.<br />

Exercise 8: Implementation of interfaces Using the class Point in the DocSharing area labeled<br />

“Using interfaces," write an application that declares an array of Points, fills the array with<br />

random points, and finds the smallest point in the array.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!