943,706 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 2119
  • Java RSS
Nov 15th, 2007
0

Need help with a very simple Java program

Expand Post »
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
Similar Threads
Reputation Points: 23
Solved Threads: 0
Newbie Poster
Magda is offline Offline
14 posts
since Jan 2007
Nov 15th, 2007
0

Re: Need help with a very simple Java program

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

Did you have any other specific questions?
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,757 posts
since May 2007
Nov 15th, 2007
0

Re: Need help with a very simple Java program

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
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
Reputation Points: 23
Solved Threads: 0
Newbie Poster
Magda is offline Offline
14 posts
since Jan 2007
Nov 15th, 2007
0

Re: Need help with a very simple Java program

Click to Expand / Collapse  Quote originally posted by 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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,757 posts
since May 2007
Nov 15th, 2007
0

Re: Need help with a very simple Java program

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
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;
}
Reputation Points: 23
Solved Threads: 0
Newbie Poster
Magda is offline Offline
14 posts
since Jan 2007
Nov 15th, 2007
0

Re: Need help with a very simple Java program

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;
}
}
Last edited by londonlad; Nov 15th, 2007 at 5:47 pm.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
londonlad is offline Offline
1 posts
since Nov 2007
Nov 15th, 2007
1

Re: Need help with a very simple Java program

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
Reputation Points: 23
Solved Threads: 0
Newbie Poster
Magda is offline Offline
14 posts
since Jan 2007
Dec 7th, 2007
0

Re: Need help with a very simple Java program

Click to Expand / Collapse  Quote originally posted by londonlad ...
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;
}
}

..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Joey Bumba is offline Offline
1 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: PacMan Boolean Problem Part Duex.
Next Thread in Java Forum Timeline: Java ME





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC