DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Need help with a very simple Java program (http://www.daniweb.com/forums/thread96892.html)

Magda Nov 15th, 2007 1:28 pm
Need help with a very simple Java program
 
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

Ezzaral Nov 15th, 2007 1:49 pm
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?

Magda Nov 15th, 2007 2:11 pm
Re: Need help with a very simple Java program
 
Quote:

Originally Posted by Ezzaral (Post 470551)
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

Ezzaral Nov 15th, 2007 2:30 pm
Re: Need help with a very simple Java program
 
Quote:

Originally Posted by Magda (Post 470560)
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.

Magda Nov 15th, 2007 4:51 pm
Re: Need help with a very simple Java program
 
Quote:

Originally Posted by Ezzaral (Post 470573)
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;
}

londonlad Nov 15th, 2007 5:46 pm
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;
}
}

Magda Nov 15th, 2007 5:57 pm
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

Joey Bumba Dec 7th, 2007 1:52 pm
Re: Need help with a very simple Java program
 
Quote:

Originally Posted by londonlad (Post 470722)
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;
}
}


..


All times are GMT -4. The time now is 6:10 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC