Hi all,

I need to write this program today and I really struggle :-( Would you be able to help at all?

public class ISPN
{
   private int[] authorId;
   private int[] programId;

   /**
    * Creates a new instance of ISPN
    */
   public ISPN(int[] anAuthorId, int[] aProgramId) //constructor that takes two array arguments and uses them to set the values of author/program identifier)
   {
      // TODO

   }

   public boolean isValidLength()  //method that returns true if author id and program id together compromise 6 integers, otheriwse false
{

      return false;
   }

   public boolean isAllValidDigits() //method that returns true if author id and program id are in the valid range 0-9 inclusive, otherwise returns false

   {
      // TODO
      return false;
   }

   public String getAuthorIdAsString()//method that returns string constructed by the digits in the array that represents author identifier
   {
      // TODO
      return null;
   }

   public String getProgramIdAsString()
   {
      // TODO
      return null;
   }

   public int calculateCheckDigit() //method that calculates the check digit and returns it as an int value
   {
      // TODO
      return 0;
   }

   public String toString()
   {
      // TODO
      return null;
   }

   public boolean equals(ISPN ispn)
   {
      // TODO
      return false;
   }   
}

Many thanks

Magda

Sure, the first thing that would help is filling in those methods a bit more.

Did you have any other specific questions?

Sure, the first thing that would help is filling in those methods a bit more.

Did you have any other specific questions?

Yes, please find the question below:

"imagine there's a proposal to develop an International Standard Program Number. Suppose the draft standard shall have the following structire:
an ISPN is always 8 characters long not counting the hyphens

- character 1 is an uppercase P to denote Program
- characters 2-7 are decimal digits representing an author identifier and program identifier. These are of variable length
- character 8 is a check digit in the range 0-8; the check digit is calculated by adding up all the digits of the author identifier and program identifier and then taking the reminder when the total is divided by 9, the check digit can larter be used to detect mistakes in copying the ISPN.

The class should contain the following methods:

1. a constructor that takes two array arguments and used them to set values of the author/program id
2. a method isValidLenght() that returns true if the author/program id together comprise 6 integegers, otherwise returns false
3. a method isAllValidDigits() that returns true if all the int values of author/program id are in the valid range 0-9 inclusive
4. a method getAuthorIdAsString that returns a string constructed by the digits in the author id array
5. a method getProgramIdAsString
6. a method calculateCheckDigit that calculates the check digit and returns it as an int value
7. a method toString that returns a string representing the ISPN

Many thanks

Magda

Yes, please find the question below:
<snipped>

No, posting your homework assignment does not constitute specific questions. You need to make an effort to complete the assignment on your own. If you have difficulties, then post the code and the errors or questions you cannot figure out.

No, posting your homework assignment does not constitute specific questions. You need to make an effort to complete the assignment on your own. If you have difficulties, then post the code and the errors or questions you cannot figure out.

Of course I'd prefer to know how to do it than ask you for a solution.

This is what I've got :

package tma01q1;

public class ISPN
{
   private int[] authorId;
   private int[] programId;

   /**
    * Creates a new instance of ISPN
    */
   public ISPN(int[] anAuthorId, int[] aProgramId)
   {
      //here i am not sure how to declare array arguments

   }

   public boolean isValidLength()
   {
     while
     {
         anAuthorId + aProgramID == 6
     }
      return true;
   }

   public boolean isAllValidDigits()
   {
      while
      {
          (anAuthorID >= 0 && anAuthorID <= 9) && (aProgramID >= 0 && aProgramID <= 9)
      }
      return true;
   }

hi there,

I am stuck at somewhere same.

/* ISPN.java
 * A class to represent an imaginary "International Standard Program Number"

 */

package tma01q1;

public class ISPN
{
   private int[] authorId;
   private int[] programId;

   /**
    * Creates a new instance of ISPN
    */
   public ISPN(int[] anAuthorId, int[] aProgramId)
   {
      authorId = anAuthorId[] ;
      programId = aProgramId[] ;
   }

   public boolean isValidLength()
   {
    if ((authorId.length + programId.length) == 6)


      return true;

      }

   public boolean isAllValidDigits()
   {
      // TODO
      return false;
   }

   public String getAuthorIdAsString()
   {
      // TODO
      return null;
   }

   public String getProgramIdAsString()
   {
      // TODO
      return null;
   }

   public int calculateCheckDigit()
   {
      // TODO
      return 0;
   }

   public String toString()
   {
      // TODO
      return null;
   }

   public boolean equals(ISPN ispn)
   {
      // TODO
      return false;
   }   
}

Many thanks for all your help. I've decided to give up on it today...will have a lesson for the future to do my assignments at least one week before the cut off date.

Take care,

Magda

commented: good idea! +13

hi there,

I am stuck at somewhere same.

/* ISPN.java
 * A class to represent an imaginary "International Standard Program Number"

 */

package tma01q1;

public class ISPN
{
   private int[] authorId;
   private int[] programId;

   /**
    * Creates a new instance of ISPN
    */
   public ISPN(int[] anAuthorId, int[] aProgramId)
   {
      authorId = anAuthorId[] ;
      programId = aProgramId[] ;
   }

   public boolean isValidLength()
   {
    if ((authorId.length + programId.length) == 6)


      return true;

      }

   public boolean isAllValidDigits()
   {
      // TODO
      return false;
   }

   public String getAuthorIdAsString()
   {
      // TODO
      return null;
   }

   public String getProgramIdAsString()
   {
      // TODO
      return null;
   }

   public int calculateCheckDigit()
   {
      // TODO
      return 0;
   }

   public String toString()
   {
      // TODO
      return null;
   }

   public boolean equals(ISPN ispn)
   {
      // TODO
      return false;
   }   
}

end quote.

..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.