#New to java and using gradle build - need some help with why my building is failing

1 messages · Page 1 of 1 (latest)

lilac pumice
#

I'm getting warnings about throwing exceptions from constructors, indentation issues in comments, and inefficient use of Random objects. Also, some tests are failing, likely due to IllegalArgumentException errors.

pastel bobcatBOT
#

<@&987246399047479336> please have a look, thanks.

lilac pumice
#

package assignmentone;

/**
 * This is Javadoc comment.
 */
public class Album {
  // Declare private attributes
  private String name;
  private int releaseYear;
  private String artist;

  /**
   * This is Javadoc comment.
   */
  
  public Album(String name, int releaseYear, String artist) {
    // Guard against improper values
    if (name != null && name.length() >= 4) {
      this.name = name;
    } else {
      this.name = "No name";
    }

    if (releaseYear >= 1800 && releaseYear <= 2029) {
      this.releaseYear = releaseYear;
    } else {
      throw new IllegalArgumentException("Invalid releaseyear input");
    }

    if (artist != null) {
      this.artist = artist;
    } else {
      this.artist = "No artist";
    }
  }

  /** 
 * Setters and getters methods. 
 */
  public void setName(String newName) {
    if (newName != null && newName.length() >= 4) {
      this.name = newName;
    } else {
      this.name = "No name";
    }
  }
  /** 
   * Returns the name of the album.
 *
 * @return the name of the album
 */
  
  public String getName() {
    return name;
  }

  /** 
   * Sets the release year of the album.
 */
  public void setYear(int releaseYear) {
    if (releaseYear >= 1800 && releaseYear <= 2029) {
      this.releaseYear = releaseYear;
    } else {
      this.releaseYear = -1;
      throw new IllegalArgumentException("Invalid releaseyear input");
    }
    this.releaseYear = releaseYear; 
    
  }

  public int getYear() {
    return releaseYear;
  }

  /**
 * Sets the artist for this object.
 *
 * @param artist the name of the artist
 */
  public void setArtist(String artist) {
    if (artist != null) {
      this.artist = artist;
    } else {
      this.artist = "No artist";
    }
  }

  /**
   * Returns the artist of the album.
   *
   * @return the artist of the album
  */
  public String getArtist() {
    return artist;
  }


}

split inlet
#

have you checked these testcases?


AlbumGeneratorTest > testAlbumGenerator() FAILED
    java.lang.IllegalArgumentException at AlbumGeneratorTest.java:17

AlbumTest > testSetYearTooLow() FAILED
    org.opentest4j.AssertionFailedError at AlbumTest.java:60

AlbumTest > testSetArtistToShort() FAILED
    org.opentest4j.AssertionFailedError at AlbumTest.java:84

AlbumTest > testSetYearTooHigh() FAILED
    java.lang.IllegalArgumentException at AlbumTest.java:67
split inlet
#

Ok, so you do get why your build is failing?

lilac pumice
#

not really

split inlet
#

your build fails because some testcases fail

lilac pumice
split inlet
#

the red text shows that, given the line you seemingly have an album with year -1

lilac pumice
#

i knew what that meant and i corrected that before but it was still showing the same error

lilac pumice