Skip to content

This is a repository containing the codes and the logic behind the 2nd assignment of the Programming 2 class, Hanoi University.

Notifications You must be signed in to change notification settings

NotAProPilot/PR2_Assignment2

Repository files navigation

Task requirements

Prerequistes

  • Complete the following tasks:
    • Create a package named a2_sidas shown in Figure 1, where sidis your student id. For example, if your student id is 123456789 then the package name is a2_123456789.
    • You will need to use this package to store all the Java class(es) that you create for the program.
    • Copy to this package two classes (PCProgand Set) that are provided in the attached zip file. Fix the import statements in these classes to match your package name.
    • The subsequent tasks will explain what you need to do with these classes. The design of class Setwas explained in the coursebook.

Important notice:

  • Failure to name the package as described above will result in an invalid program.
  • You must use the necessary utility classes in the utils package (provided as part of the lecture resources). This package should be created as another top-level package as shown in Figure 1. You must not create package utilsas a sub-package of your package.
  • In addition, you must not include package utils as part of your submission.
  • You may use JDK version 8 or 11 only.

Specify and implement class PC.

  • PCmust contain the essential state and behaviour spaces.
  • PCmust appropriately use Setin its design.
  • You must implement PC.toString() such that the outputs look like the example shown in Section 1.
  • You must override the equals()method for PC, which determines equality of two PCobjects based on their states.

Specify and implement class PCFactory that has a factory method for creating PCs.

  • This class must also be a singleton. You must strictly follow the relevant design pattern solutions.

Specify and implement class PCReportwhich contains a single operation:

displayReport(PC[] objs): String

  • Note the following:
    1. The report format must be as specified in Listing 1.
    2. This class has no instance variables.

Specify for the PCProg (partially completed)

  • A partially completed class named PCProg is provided for testing your program. Move it into your a2_sidpackage so that you can run it.

  • Class PCProgcontains the main method and some operations for performing the tasks highlighted in Section 1:

    • Attribute objsis typed Setand used to record PC objects.
    • createObjects: uses PCFactory to create a new PC object and record it in objs. Method createObjectsshould not invoke PCconstructor directly.
    • getObjects: return the recorded PC objects.
    • displayReport: uses PCReportto generate and display the tabular report about PC objects.
    • saveReport: save the report text to file.
    • main: create a new PCProgobject and run its operations.
  • Some notes about the PC Prog class:

    • The following procedures are completed and provided for you: displayReport, saveReportand, and main. You must not change them.
    • In order to make the program work, you need to specify and implement the operations createObjectsand and getObjects.

Submission requirements

  1. Create a zip file containing just the folder of the required package. You must name the file as follows: a2_sid.zip, where sidis your student id. Submit your file to the designated submission box.
  2. In particular, ONLY the ZIP format is accepted. Other formats (e.g. RAR) are NOT accepted. IMPORTANT: Failure to name the file as described above will result in an invalid program.

Frequently Asked Questions (FAQs)

  1. Specify and implement class PCFactory that has a factory method for creating PCs. This class must also be a singleton. What is a singleton?
  • Singleton pattern concerns classes that have only one object.
  • Most simple singleton (for the purpose of this assignment) use the following:
class A{  
 private static A obj=new A();//Early, instance will be created at load time  
 private A(){}  
   
 public static A getA(){  
  return obj;  
 }  
  
 public void doSomething(){  
 //write your code  
 }  
}  
  1. Can integer be null?
  • You must be here from Tutorial 9 documentation.
  • A short answer would be this:

    In Java, int is a primitive type and it is not considered an object. Only objects can have a null value. So the answer to your question is no, it can't be null. But it's not that simple, because there are objects that represent most primitive types.

Update:

  • This assignment was graded 8.5/10. Not bad, but for the effort I put in, this is quite.. sad.
  • Since it is graded, you can copy it anyway. Tried my best to document this code. Good luck class of '22!

About

This is a repository containing the codes and the logic behind the 2nd assignment of the Programming 2 class, Hanoi University.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages