1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java Programming Question

  1. Oct 6, 2011 #1
    1. The problem statement, all variables and given/known data
    Write an application that inputs ten numbers from the user, each number can be between 10 and 100, inclusive. As each number is read in determine if it is a number already entered. If it is a duplicate move on to the next number, if it is unique store the number in the array. After all ten numbers have been entered display the complete set of unique numbers that were entered.



    2. Relevant equations
    Im trying to make a reusable class but I dont know how to really do it so I have been just trying everything and I seem to just not get it I need some help to understand this



    3. The attempt at a solution
    public class Arrayclass {

    }
    public static void main(String[] args) {

    }
    public static boolean arrayDupeCheck(int[] array, int dupeNumber) {

    }
     
  2. jcsd
  3. Oct 6, 2011 #2

    Mark44

    Staff: Mentor

    Classes are by nature reusable. Where in the problem description does it say that you have to write a class of any kind?


     
  4. Oct 6, 2011 #3
    In this problem I need to make a reusable class and a test class the resuable class and the test class are two diffrent classes that make the program work im new to netbeans programming and this is something that is confusing to me one file will be declaring the varibales and the other is the run file i hope this helps as i said im new to this and looking for help trying to understand this myself
    My program i set up ilike this
    Starting the program
    import java.util.Scanner
    Declare variables
    create array with 10 elements
    create Scanner object
    Allow user to set all numbers in array
    Initialize counter
    Ask until user enters a unique number
    do
    User friendly error message if number is the same as another entered
    Check to make sure user input valid number
    Request new number if any number is negative
    while
    Call array method to check user input for duplicates & display error message
    for
    assign user input to index (number) of array
    Print all array elements
    Method for loop to check for duplicate entries to array
    public static boolean
    return true
    return false

    But then I need to make a reusable class that goes with this im confused on how to start to write a reusable class that goes along with this in a seperate file
    this is the complete question

    (Must be implemented using a one-dimensional array.)

    Write an application that inputs ten numbers from the user, each number can be between 10 and 100, inclusive. As each number is read in determine if it is a number already entered. If it is a duplicate move on to the next number, if it is unique store the number in the array. After all ten numbers have been entered display the complete set of unique numbers that were entered.

    But it needs a reuasble class then a test class so this would make 2 files to work i worte the program which is one file and it works but I dont understand the part about a reuseable class that goes with it? Am I going to make another file that describes the varibales that make my program work? Thank You Seems like you are all great People here
     
    Last edited: Oct 6, 2011
  5. Oct 6, 2011 #4

    Mark44

    Staff: Mentor

    Your problem statement says, "Write an application that ..."

    It doesn't say anything about classes. Have you given us the complete problem statement?
     
  6. Oct 7, 2011 #5
    This is my Psuedocode for this program

    CREATE public class SingleArray

    DECLARE number array as integer and set as single dimensional with 10 elements



    CREATE public SingleArray and set all numbers/elements to -1



    CREATE public void setNumber method to store the values passed in



    CREATE public boolean checkValue with val parameter

    IF the value entered is between 10 and 100 statement is true

    ELSE the statement is false



    CREATE public int checkDuplicate and verify if number is already entered

    IF value is equal to previous value stored

    CONTINUE loop to next value



    PRINT a message to the user with all unique numbers entered



    -----------------------------------------------------

    SINGLE ARRAY TEST PSEUDOCODE

    -----------------------------------------------------



    IMPORT Scanner for input



    CREATE public class SingleArray



    CREATE public static void main



    CREATE new instance of SingleArray and Scanner



    WHILE counter is less than or equal to ten

    PROMPT user for next integer



    CALL the checkValue method from reusable class



    IF the statement returns true



    CALL the checkDuplicate method from reusable class



    IF the statement also returns true



    CALL the method setNumber from the reusable class



    ELSE



    PRINT the value needs to be between 10 and 100



    DISPLAY the Array method from the reusable class



    END main method



    END SingleArray class

    I hope this helps to show what I need help with Thank You
     
    Last edited: Oct 7, 2011
  7. Oct 7, 2011 #6

    Mark44

    Staff: Mentor

    Please stop describing your class as "reusable" like it means something. Classes are generally reusable, so describing one this way doesn't add any information.

    Let's look at your SingleArray class.
    From this information, I infer that the SingleArray class should have a private data member that is a 10-element array of type int. It's not clear to me what the name should be - number?

    There should be a default constructor named SingleArray (no arguments), that sets each element of the array to -1.

    There should be a public method named setNumber that returns void (i.e., doesn't return a value). Your description of what it should do is to vague for me to understand what it's supposed to do. Should this method have a parameter?

    There should be a public method named checkValue that returns a bool value. It has a single parameter named val. If val is between 10 and 100 this method returns true. Otherwise, it returns false. (Not, as you have it "statement is true" and "statement is false".)

    There should be a public method named checkDuplicate that returns an int. Your description doesn't say whether it should have a parameter or not, and your description of what it should do is incorrect. My guess is that it should take a parameter, and that it should compare the parameter value to each value already in the array. You don't have any information about what this method should return. The problem description as given to you should have this information.

    Your next step should be coming up with algorithms or pseudocode for the class constructor and the three other methods listed above. Be careful to use exactly these names, because your instructor is likely to deduct points if your give them different names.
     
  8. Oct 7, 2011 #7
    Wow ThankYou I learned more form your help than my instructor now i can use this information to help complete my assignment this is a great place for help Thank You
     
  9. Oct 7, 2011 #8

    Mark44

    Staff: Mentor

    Glad to help!

    One thing that will help you when you communicate with others is USE SOME PUNCTUATION! In what you wrote above, there is not a single punctuation mark. When you start writing your Java code, you are going to need to put semicolons (;) at the end of statements, and you'll need to use commas occasionally.

    What you write in English will be easier to understand if you put a period at the end of each sentence.

    Also, if you need more help with your Java code, put a [ code ] tag at the beginning and a [ /code ] tag at the end of your code (leave out the spaces, though. These are HTML tags, so if I write them without spaces, they don't show up.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Java Programming Question
  1. Java programming (Replies: 4)

  2. Java program (Replies: 3)

Loading...