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

Define a class to model digital media. Sound, images, text and video are all ava

ID: 3784033 • Letter: D

Question

Define a class to model digital media. Sound, images, text and video are all available in digital format for use on a computer system. The class DigitalMedia is a generalization of these kinds of files. It has four fields: name(String), size(long), dateCreated(LocalDateTime), and dateModified(LocalDateTime).

Design the class so that individual instances never contain null fields. Because there are no valid default values, to not include a parameterless constructor for the class.

The parameterized constructor must validate all parameters before creating the instance. The DigitalMedia class will be graded using a jUnit test class, so the order of the parameters needs to match the test class. Use this method header for the parameterized constructor:

public DigitalMedia (String name, long size)

Implement accessor (getter) and mutator (setter) methods for each of the instance variables, except for the dateCreated (that field is immutable, so only write the getter method) using the standard naming conventions. In addition, define the following methods:

public boolean equals(Object other)

public String toString()

The equals method overrides the one that is inherited from the Object class, therefore the method signature must match exactly – the parameter must be of type Object. Two DigitalMedia objects are equal if they have the same state as represented by the four fields. Guidelines for overriding the equals method:

Use the == operator to check if the argument is a reference to itself.

Use the instanceof operator to check if the argument has the correct data type.

Cast the argument to the correct type.

For each significant data member, test for equality.

Test these three properties:

o Is it symmetric?

o Is it transitive?

o Is it consistent?

Complete and submit a test plan following the example provided to thoroughly test all of the methods in your

DigitalMedia class
Implement the DigitalMediaTester.java program containing a main method with code written to implement

the test plan.
Your source code files name should be DigitalMedia.java and DigitalMediaTester.java.

Explanation / Answer

DigitalMedia.java


import java.time.LocalDateTime;


public class DigitalMedia {
    private String name;
    private long size;
    private LocalDateTime dateCreated;
    private LocalDateTime dateModified;
  
    public DigitalMedia(String name, long size, LocalDateTime dateCreated,
            LocalDateTime dateModified) {
        this.name = name;
        this.size = size;
        this.dateCreated = dateCreated;
        this.dateModified = dateModified;
    }
  
    public void setName(String name) {
        this.name = name;
    }
  
    public String getName() {
        return this.name;
    }
  
    public void setSize(long size) {
        this.size = size;
    }
  
    public long getSize() {
        return this.size;
    }
  
    public LocalDateTime getDateCreated() {
        return this.dateCreated;
    }
  
    public void setDateModified(LocalDateTime dateModified) {
        this.dateModified = dateModified;
    }
  
    public LocalDateTime getDateModified() {
        return this.dateModified;
    }
  
    @Override
    public boolean equals(Object MyBook) {
        if (MyBook instanceof DigitalMedia) {
            if (((DigitalMedia)MyBook).getDateCreated() == this.getDateCreated() &&
                    ((DigitalMedia)MyBook).getDateModified() == this.getDateModified() &&
                    ((DigitalMedia)MyBook).getName() == this.getName() &&
                    ((DigitalMedia)MyBook).getSize() == this.getSize()) {
                return true;
            } else return false;
        } else return false;
    }
  
    /**
     * toString()
     *
     * @return
     */
    public String toString() {
        return "Name: " + this.name +
                " Size: " + this.size +
                " Date Created: " + this.dateCreated.toString() +
                " Date Modified: " + this.dateModified.toString();
    }
}


DigitalMediaTester.java


import java.time.LocalDateTime;


public class DigitalMediaTester {
  
  
  
    public static void main(String[] args) {
        DigitalMedia test;
      
        test = new DigitalMedia("RandomFile.pdf", 5, LocalDateTime.now(), LocalDateTime.now());
      
        System.out.println(test.toString());
      
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote