Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part I: The Design In this section, you are asked to finish the design of a comp

ID: 3895968 • Letter: P

Question

Part I: The Design

In this section, you are asked to finish the design of a computer program according to the information and instructions given below. A Registry is thought of as a store where you can remember objects. You can add a member to a registry, print the contents of the registry, and sort its members. Registry is a Java interface: it is a specification. In this lab, you are going to write an interface called Registry that has three abstract methods: print(), sort(), and addMember(Comparable object).

GenericRegistry is an abstract class that partially implements the Registry interface. This class implements addMember, and sort, has storage for the members and the number of elements, but the print method is not implemented. The implementation of an interface relationship is represented in UML by dotted big hollow arrow.

The arrow is at the interface side.

Now, connect the GenericRegistry to the Registry in the diagram given in Figure 1 using the above symbol.The arrow is at the interface side.

StudentRegistry is a concrete class that extends the abstract class GenericRegistry. It is used for storing students. It implements the print() method; it borrows most of its functionality from GenericRegistry. At this level, all the methods declared by the interface Registry are defined. Thus we are able to instantiate objects from this class. The graphic notation of an abstract class is to italicize the name of the class; and the relationship for inheriting an abstract class is represented in UML by a big hollow arrow.

The arrow is at the abstract class side.

Now, connect the GenericRegistry to the StudentRegistry using the above symbol.The arrow is at the abstract class side.

The Student class implements the Comparable interface of Java. Comparable is a Java interface supplied by the compiler. This interface contains one abstract method header “int compareTo(Comparable).” This method is used to compare two objects. In order to use it, each object involved must implement the interface Comparable. The following is an example of using it:

            object1.compareTo(object2)

The result returned by the compareTo method is an integer and its value depends on the following rules:

1. Has a negative value if object1 is less than object2.

2. Has the value 0 if object1 is equal to objec2.

3. Has a positive value if object1 is greater than object2.

Now, connect the Student class to the Comparable interface by using dotted big hollow arrow.

Student class is a component of StudentRegistry class. Thus, connect the Student with StudentRegistry by using the follow composition symbol.

The solid shape is at the container side. Draw the above connection between the Student and the StudentRegistry and make sure that the solid shape is at the StudentRegistry side.

SCORE YOUR POINTS BY DOING THE FOLLOWING

Complete the diagram by drawing the relationships among classes and the interfaces (5 pts).

Figure 1: partially finished UML diagram.

Part II: Completing the Implementation

Preparation knowledge:

Array in Java is a collection of same data type that is organized together. Each cell (or element) is referred to by an array index. For example, suppose that we have an array named a, then the first element of a will be a[0]. In this lab, we give you the first exposure to this data type. All you need to know is go through every element in an array using a for loop as shown in the following (in the following code, suppose that the count is the actual number of elements stored in the array (not the array length); also assume that the type of array is Student):

for (int index = 0; index < count; index++) {

       System.out.println(a[index]);

}

The above segment of code will go through each Student object and call the object’s toString() method.

Your work

In this section, you are asked to implement the above design and do some screen captures of the outputs. You are given partial code and you need to finish the missing code. To finish the lab work in this section, you can follow the following steps:

Create a project named lab4 in Eclipse.

Cut and paste the classes given by create class names first in Eclipse; then cut the code in this documentation; and paste them into the appropriate part of the Eclipse. Note: make sure that you deleted all the hidden characters after pasting.

Create missing classes and interfaces.

Debug and run the application.

Specifically, you are given the following code:

            class GenericRegistry

            class Student

            application class Lab4

           

And you need to supply the code for the following classes and interfaces:

            interface Registry

            class StudentRegistry

The following is the code for Student, GenericRegistry, and the application class Lab4:

public abstract class GenericRegistry implements Registry {

       protected Comparable[] members;

       protected int count;

       public void addMember(Comparable object) {

              members[count++] = object;

       }

       // Selection sort

       public void sort() {

              for (int i = 0; i < count - 1; i++) {

                     int min = i;

                     for (int j = i + 1; j < count; j++) {

                           if (members[min].compareTo(members[j]) > 0) {

                                  min = j;

                           }

                     }

                     Comparable object = members[i];

                     members[i] = members[min];

                     members[min] = object;

              }

       }

}

Note: the storage in this class is an array of Comparable objects. Thus, any objects to be stored in the array should be a type of Comparable. Since Student implements Comparable, thus Student can be stored in the array as well.

public class Student implements Comparable {

       private String name;

       private String major;

       public Student(String name, String major) {

              this.name = name;

              this.major = major;

       }

       public String getName() {

              return name;

       }

       public String getMajor() {

              return major;

       }

       public int compareTo(Object student) {

              return name.compareTo(((Student) student).name);

       }

       public String toString() {

              return "Name: " + name + " major " + major;

       }

}

Note: this class implements the Comparable interface. Thus, it can be stored in the array called “members” in the GenericRegistry. An interface is also a type. When a class implements an interface, the class will have two types. In this case, the class Student is both a type of Student and a type of Comparable.

public class Lab4 {

       public static void main(String[] s) {

              StudentRegistry sr = new StudentRegistry(10);

              sr.addMember(new Student("Close", "English"));

              sr.addMember(new Student("Snow", "Physics"));

              sr.addMember(new Student("Lal", "Physics"));

              sr.addMember(new Student("Chow", "English"));

              sr.print();

              sr.sort();

              System.out.println();

              sr.print();

       }

}

Note: we allocate 10 cells for the array members. This is the largest number of Student objects that can be stored in the array. When you write the print() method for the class StudentRegistry, you should use the instance variable count in the class GenericRegistry to decide the actual number of items in the array members (not the array length!).

SCORE YOUR POINTS BY DOING THE FOLLOWING:

Cut and paste the Java source code of StudentRegistry.java and Registry.java in the space below (5 pts):

Cut and paste the output in the space below (5 pts):

Explanation / Answer

StudentRegistry.java

class studentRegistration{

  

public static void main(String[] args){

  

  

student stnt1,stnt2,stnt3;

String stntName1,stntName2,stntName3,stntName4;

  

stnt1 = new student();

stnt2 = new student();

stnt3 = new student();

  

stnt1.setStudentName("Robinroy");

stnt2.setStudentName("Kalai");

stnt3.setStudentName("Nopert");

  

stnt1.setStudentMarks_Sub1(45);

stnt2.setStudentMarks_Sub1(65);

stnt3.setStudentMarks_Sub1(75);

  

stnt1.setStudentMarks_Sub2(25);

stnt2.setStudentMarks_Sub2(42);

stnt3.setStudentMarks_Sub2(78);   

  

stnt1.setStudentMarks_Sub3(12);

stnt2.setStudentMarks_Sub3(45);

stnt3.setStudentMarks_Sub3(36);

  

stntName1 =stnt1.getStudentName();

stntName2 =stnt2.getStudentName();

stntName3 =stnt3.getStudentName();

System.out.println(stntName2+"'s Total is "+stnt2.setStudentMarks_Total());

}

}

Registry.java

import java.util.HashMap;

import java.util.Map;

import org.osgeo.proj4j.datum.Datum;

import org.osgeo.proj4j.datum.Ellipsoid;

import org.osgeo.proj4j.proj.*;

public class Registry {

public Registry() {

super();

initialize();

}

public final static Datum[] datums =

{

Datum.WGS84,

Datum.GGRS87,

Datum.NAD27,

Datum.NAD83,

Datum.POTSDAM,

Datum.CARTHAGE,

Datum.HERMANNSKOGEL,

Datum.IRE65,

Datum.NZGD49,

Datum.OSEB36

};

public Datum getDatum(String code)

{

for ( int i = 0; i < datums.length; i++ ) {

if ( datums[i].getCode().equals( code ) ) {

return datums[i];

}

}

return null;

}

public final static Ellipsoid[] ellipsoids =

{

Ellipsoid.SPHERE,

new Ellipsoid("MERIT", 6378137.0, 0.0, 298.257, "MERIT 1983"),

new Ellipsoid("SGS85", 6378136.0, 0.0, 298.257, "Soviet Geodetic System 85"),

Ellipsoid.GRS80,

new Ellipsoid("IAU76", 6378140.0, 0.0, 298.257, "IAU 1976"),

Ellipsoid.AIRY,

Ellipsoid.MOD_AIRY,

new Ellipsoid("APL4.9", 6378137.0, 0.0, 298.25, "Appl. Physics. 1965"),

new Ellipsoid("NWL9D", 6378145.0, 298.25, 0.0, "Naval Weapons Lab., 1965"),

new Ellipsoid("andrae", 6377104.43, 300.0, 0.0, "Andrae 1876 (Den., Iclnd.)"),

new Ellipsoid("aust_SA", 6378160.0, 0.0, 298.25, "Australian Natl & S. Amer. 1969"),

new Ellipsoid("GRS67", 6378160.0, 0.0, 298.2471674270, "GRS 67 (IUGG 1967)"),

Ellipsoid.BESSEL,

new Ellipsoid("bess_nam", 6377483.865, 0.0, 299.1528128, "Bessel 1841 (Namibia)"),

Ellipsoid.CLARKE_1866,

Ellipsoid.CLARKE_1880,

new Ellipsoid("CPM", 6375738.7, 0.0, 334.29, "Comm. des Poids et Mesures 1799"),

new Ellipsoid("delmbr", 6376428.0, 0.0, 311.5, "Delambre 1810 (Belgium)"),

new Ellipsoid("engelis", 6378136.05, 0.0, 298.2566, "Engelis 1985"),

Ellipsoid.EVEREST,

new Ellipsoid("evrst48", 6377304.063, 0.0, 300.8017, "Everest 1948"),

new Ellipsoid("evrst56", 6377301.243, 0.0, 300.8017, "Everest 1956"),

new Ellipsoid("evrst69", 6377295.664, 0.0, 300.8017, "Everest 1969"),

new Ellipsoid("evrstSS", 6377298.556, 0.0, 300.8017, "Everest (Sabah & Sarawak)"),

new Ellipsoid("fschr60", 6378166.0, 0.0, 298.3, "Fischer (Mercury Datum) 1960"),

new Ellipsoid("fschr60m", 6378155.0, 0.0, 298.3, "Modified Fischer 1960"),

new Ellipsoid("fschr68", 6378150.0, 0.0, 298.3, "Fischer 1968"),

new Ellipsoid("helmert", 6378200.0, 0.0, 298.3, "Helmert 1906"),

new Ellipsoid("hough", 6378270.0, 0.0, 297.0, "Hough"),

Ellipsoid.INTERNATIONAL,

Ellipsoid.INTERNATIONAL_1967,

Ellipsoid.KRASSOVSKY,

new Ellipsoid("kaula", 6378163.0, 0.0, 298.24, "Kaula 1961"),

new Ellipsoid("lerch", 6378139.0, 0.0, 298.257, "Lerch 1979"),

new Ellipsoid("mprts", 6397300.0, 0.0, 191.0, "Maupertius 1738"),

new Ellipsoid("plessis", 6376523.0, 6355863.0, 0.0, "Plessis 1817 France)"),

new Ellipsoid("SEasia", 6378155.0, 6356773.3205, 0.0, "Southeast Asia"),

new Ellipsoid("walbeck", 6376896.0, 6355834.8467, 0.0, "Walbeck"),

Ellipsoid.WGS60,

Ellipsoid.WGS66,

Ellipsoid.WGS72,

Ellipsoid.WGS84,

new Ellipsoid("NAD27", 6378249.145, 0.0, 293.4663, "NAD27: Clarke 1880 mod."),

new Ellipsoid("NAD83", 6378137.0, 0.0, 298.257222101, "NAD83: GRS 1980 (IUGG, 1980)"),

};

public Ellipsoid getEllipsoid(String name)

{

for ( int i = 0; i < ellipsoids.length; i++ ) {

if ( ellipsoids[i].shortName.equals( name ) ) {

return ellipsoids[i];

}

}

return null;

}

private Map<String, Class> projRegistry;

private void register( String name, Class cls, String description ) {

projRegistry.put( name, cls );

}

public Projection getProjection( String name ) {

// if ( projRegistry == null )

// initialize();

Class cls = (Class)projRegistry.get( name );

if ( cls != null ) {

try {

Projection projection = (Projection)cls.newInstance();

if ( projection != null )

projection.setName( name );

return projection;

}

catch ( IllegalAccessException e ) {

e.printStackTrace();

}

catch ( InstantiationException e ) {

e.printStackTrace();

}

}

return null;

}

  

private synchronized void initialize() {

// guard against race condition

if (projRegistry != null)

return;

projRegistry = new HashMap();

register( "aea", AlbersProjection.class, "Albers Equal Area" );

register( "aeqd", EquidistantAzimuthalProjection.class, "Azimuthal Equidistant" );

register( "airy", AiryProjection.class, "Airy" );

register( "aitoff", AitoffProjection.class, "Aitoff" );

register( "alsk", Projection.class, "Mod. Stereographics of Alaska" );

register( "apian", Projection.class, "Apian Globular I" );

register( "august", AugustProjection.class, "August Epicycloidal" );

register( "bacon", Projection.class, "Bacon Globular" );

register( "bipc", BipolarProjection.class, "Bipolar conic of western hemisphere" );

register( "boggs", BoggsProjection.class, "Boggs Eumorphic" );

register( "bonne", BonneProjection.class, "Bonne (Werner lat_1=90)" );

register( "cass", CassiniProjection.class, "Cassini" );

register( "cc", CentralCylindricalProjection.class, "Central Cylindrical" );

register( "cea", CylindricalEqualAreaProjection.class, "Equal Area Cylindrical" );

// register( "chamb", Projection.class, "Chamberlin Trimetric" );

register( "collg", CollignonProjection.class, "Collignon" );

register( "crast", CrasterProjection.class, "Craster Parabolic (Putnins P4)" );

register( "denoy", DenoyerProjection.class, "Denoyer Semi-Elliptical" );

register( "eck1", Eckert1Projection.class, "Eckert I" );

register( "eck2", Eckert2Projection.class, "Eckert II" );

// register( "eck3", Eckert3Projection.class, "Eckert III" );

register( "eck4", Eckert4Projection.class, "Eckert IV" );

register( "eck5", Eckert5Projection.class, "Eckert V" );

register( "eck6", Eckert6Projection.class, "Eckert VI" );

register( "eqc", PlateCarreeProjection.class, "Equidistant Cylindrical (Plate Caree)" );

register( "eqdc", EquidistantConicProjection.class, "Equidistant Conic" );

register( "euler", EulerProjection.class, "Euler" );

register( "fahey", FaheyProjection.class, "Fahey" );

register( "fouc", FoucautProjection.class, "Foucaut" );

register( "fouc_s", FoucautSinusoidalProjection.class, "Foucaut Sinusoidal" );

register( "gall", GallProjection.class, "Gall (Gall Stereographic)" );

// register( "gins8", Projection.class, "Ginsburg VIII (TsNIIGAiK)" );

// register( "gn_sinu", Projection.class, "General Sinusoidal Series" );

register( "gnom", GnomonicAzimuthalProjection.class, "Gnomonic" );

register( "goode", GoodeProjection.class, "Goode Homolosine" );

// register( "gs48", Projection.class, "Mod. Stererographics of 48 U.S." );

// register( "gs50", Projection.class, "Mod. Stererographics of 50 U.S." );

register( "hammer", HammerProjection.class, "Hammer & Eckert-Greifendorff" );

register( "hatano", HatanoProjection.class, "Hatano Asymmetrical Equal Area" );

// register( "imw_p", Projection.class, "Internation Map of the World Polyconic" );

register( "kav5", KavraiskyVProjection.class, "Kavraisky V" );

// register( "kav7", Projection.class, "Kavraisky VII" );

register( "krovak", KrovakProjection.class, "Krovak" );

// register( "labrd", Projection.class, "Laborde" );

register( "laea", LambertAzimuthalEqualAreaProjection.class, "Lambert Azimuthal Equal Area" );

register( "lagrng", LagrangeProjection.class, "Lagrange" );

register( "larr", LarriveeProjection.class, "Larrivee" );

register( "lask", LaskowskiProjection.class, "Laskowski" );

register( "latlong", LongLatProjection.class, "Lat/Long (Geodetic alias)" );

register( "longlat", LongLatProjection.class, "Lat/Long (Geodetic alias)" );

register( "latlon", LongLatProjection.class, "Lat/Long (Geodetic alias)" );

register( "lonlat", LongLatProjection.class, "Lat/Long (Geodetic)" );

register( "lcc", LambertConformalConicProjection.class, "Lambert Conformal Conic" );

register( "leac", LambertEqualAreaConicProjection.class, "Lambert Equal Area Conic" );

// register( "lee_os", Projection.class, "Lee Oblated Stereographic" );

register( "loxim", LoximuthalProjection.class, "Loximuthal" );

register( "lsat", LandsatProjection.class, "Space oblique for LANDSAT" );

// register( "mbt_s", Projection.class, "McBryde-Thomas Flat-Polar Sine" );

register( "mbt_fps", McBrydeThomasFlatPolarSine2Projection.class, "McBryde-Thomas Flat-Pole Sine (No. 2)" );

register( "mbtfpp", McBrydeThomasFlatPolarParabolicProjection.class, "McBride-Thomas Flat-Polar Parabolic" );

register( "mbtfpq", McBrydeThomasFlatPolarQuarticProjection.class, "McBryde-Thomas Flat-Polar Quartic" );

// register( "mbtfps", Projection.class, "McBryde-Thomas Flat-Polar Sinusoidal" );

register( "merc", MercatorProjection.class, "Mercator" );

// register( "mil_os", Projection.class, "Miller Oblated Stereographic" );

register( "mill", MillerProjection.class, "Miller Cylindrical" );

// register( "mpoly", Projection.class, "Modified Polyconic" );

register( "moll", MolleweideProjection.class, "Mollweide" );

register( "murd1", Murdoch1Projection.class, "Murdoch I" );

register( "murd2", Murdoch2Projection.class, "Murdoch II" );

register( "murd3", Murdoch3Projection.class, "Murdoch III" );

register( "nell", NellProjection.class, "Nell" );

// register( "nell_h", Projection.class, "Nell-Hammer" );

register( "nicol", NicolosiProjection.class, "Nicolosi Globular" );

register( "nsper", PerspectiveProjection.class, "Near-sided perspective" );

register( "nzmg", NewZealandMapGridProjection.class, "New Zealand Map Grid" );

// register( "ob_tran", Projection.class, "General Oblique Transformation" );

// register( "ocea", Projection.class, "Oblique Cylindrical Equal Area" );

// register( "oea", Projection.class, "Oblated Equal Area" );

register( "omerc", ObliqueMercatorProjection.class, "Oblique Mercator" );

// register( "ortel", Projection.class, "Ortelius Oval" );

register( "ortho", OrthographicAzimuthalProjection.class, "Orthographic" );

register( "pconic", PerspectiveConicProjection.class, "Perspective Conic" );

register( "poly", PolyconicProjection.class, "Polyconic (American)" );

// register( "putp1", Projection.class, "Putnins P1" );

register( "putp2", PutninsP2Projection.class, "Putnins P2" );

// register( "putp3", Projection.class, "Putnins P3" );

// register( "putp3p", Projection.class, "Putnins P3'" );

register( "putp4p", PutninsP4Projection.class, "Putnins P4'" );

register( "putp5", PutninsP5Projection.class, "Putnins P5" );

register( "putp5p", PutninsP5PProjection.class, "Putnins P5'" );

// register( "putp6", Projection.class, "Putnins P6" );

// register( "putp6p", Projection.class, "Putnins P6'" );

register( "qua_aut", QuarticAuthalicProjection.class, "Quartic Authalic" );

register( "robin", RobinsonProjection.class, "Robinson" );

register( "rpoly", RectangularPolyconicProjection.class, "Rectangular Polyconic" );

register( "sinu", SinusoidalProjection.class, "Sinusoidal (Sanson-Flamsteed)" );

register( "somerc", SwissObliqueMercatorProjection.class, "Swiss Oblique Mercator" );

register( "stere", StereographicAzimuthalProjection.class, "Stereographic" );

register( "sterea", ObliqueStereographicAlternativeProjection.class, "Oblique Stereographic Alternative" );

register( "tcc", TranverseCentralCylindricalProjection.class, "Transverse Central Cylindrical" );

register( "tcea", TransverseCylindricalEqualArea.class, "Transverse Cylindrical Equal Area" );

// register( "tissot", TissotProjection.class, "Tissot Conic" );

register( "tmerc", TransverseMercatorProjection.class, "Transverse Mercator" );

// register( "tpeqd", Projection.class, "Two Point Equidistant" );

// register( "tpers", Projection.class, "Tilted perspective" );

// register( "ups", Projection.class, "Universal Polar Stereographic" );

// register( "urm5", Projection.class, "Urmaev V" );

register( "urmfps", UrmaevFlatPolarSinusoidalProjection.class, "Urmaev Flat-Polar Sinusoidal" );

register( "utm", TransverseMercatorProjection.class, "Universal Transverse Mercator (UTM)" );

register( "vandg", VanDerGrintenProjection.class, "van der Grinten (I)" );

// register( "vandg2", Projection.class, "van der Grinten II" );

// register( "vandg3", Projection.class, "van der Grinten III" );

// register( "vandg4", Projection.class, "van der Grinten IV" );

register( "vitk1", VitkovskyProjection.class, "Vitkovsky I" );

register( "wag1", Wagner1Projection.class, "Wagner I (Kavraisky VI)" );

register( "wag2", Wagner2Projection.class, "Wagner II" );

register( "wag3", Wagner3Projection.class, "Wagner III" );

register( "wag4", Wagner4Projection.class, "Wagner IV" );

register( "wag5", Wagner5Projection.class, "Wagner V" );

// register( "wag6", Projection.class, "Wagner VI" );

register( "wag7", Wagner7Projection.class, "Wagner VII" );

register( "weren", WerenskioldProjection.class, "Werenskiold I" );

// register( "wink1", Projection.class, "Winkel I" );

// register( "wink2", Projection.class, "Winkel II" );

register( "wintri", WinkelTripelProjection.class, "Winkel Tripel" );

}

}