Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Object Orientation Program Help.

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Object Orientation Program Help.

    I am totally lost with this program. I've been working on it for a while and still nothing. I've been to tutoring multiple times, and I am getting more confused. This program is due today and I really need help. Thank you.

    Below are two classes. The person class and the 314 class (object). Embedded in the code are comments that tell you what the professor is asking for. I have already written part of the person class.

    Person class:

    // person class

    public class person {
    private String Name;
    private char sex;
    private String score;
    private int[] grades = new int[5];
    private String newName;
    public person() // CONSTRUCTOR
    {

    }
    public void setName(String g) // RECEIVE NAME
    {Name = g; }
    public void setSex(char c) // RECEIVE SEX CODE
    {sex = c;};
    public void setScore(String cat) // RECEIVE SCORES AS STRING
    {score = cat;}
    public void fixName()
    {
    /* HERE IS WHERE YOY TAKE YOUR STRING name
    CONVERT IT TO LOWWER CASE, BREAK IT INTO 2 STRINGS
    (FIRST AND LAST), CONVERT THE FIRST LETTER OF EACH
    PART TO CAPITAL, AND CONCATENATE IT BACK TOGETHER AND
    STORE IT IN newname.
    */

    String last, first;
    first = Name.substring(1, Name.indexOf(" "));
    first = first.toLowerCase();
    first = Name.charAt(0) + first;
    newName = Name.toLowerCase();
    System.out.println(first);
    last = Name.substring(Name.indexOf(" ")+2, Name.length());
    last = last.toLowerCase();
    last = Name.charAt(Name.indexOf(" ")+1) + last;
    newName = Name.toLowerCase();
    System.out.println(last);

    }
    public void fixScore()
    {
    /*HERE YOU TAKE YOUR STRING CALLED scores ABOVE AND USE
    AND STORE IT IN YOUR INTEGER ARRAY CALLED GRADES (ABOVE).
    //10 objects sitting in this method
    //pp=(Person)vector.get(a) where a is 0-9
    */
    String score;
    //

    //grades?

    }
    public String getName() // RETURNS NEWNAME
    {return newName;}
    public char getSex() // RETURNS SEX CODE
    {return sex;}
    //---provide a function that will return the 5 scores for that person.
    //You cannot return an array reference.. find another way.
    }



    314 Class:


    import java.io.RandomAccessFile;
    import java.io.EOFException;
    import java.io.IOException;
    import java.util.Vector;

    public class First_314_Project
    {
    private RandomAccessFile raf;
    //The entire path to the location of the file
    private final String fileToRead = "DATA314.dat";
    private Vector vector = new Vector();
    private String temp;
    private int c=0;
    private person pp;
    private String[] Names = new String[10];
    private char[] Sex = new char[10];
    private int[][] Score = new int[10][5];
    private float[] averages = new float[5];
    private char[] letter = new char[10];
    public First_314_Project()
    {
    int counter=0;
    try{
    raf = new RandomAccessFile(fileToRead,"r");
    do{
    temp=raf.readUTF(); // raf is an object of the random access file class
    //System.out.println(temp);
    person p = new person();
    int c = temp.indexOf(':');
    String g = temp.substring(0,c);
    char b = temp.charAt(c+1);
    String cat = temp.substring(c+3,temp.length());
    p.setName(g);
    p.setSex(b);
    p.setScore(cat);
    p.fixName();
    //find the blank
    //get the first name
    //get the last name
    //use a substring command and grab position 1 through n-1 grab first name and leave the first letter alone
    // take them apart and concenate them to create the correct order of the names. dont forget to put the comma inbetween the two
    //last name first and then the first name
    //convert the whole thing to lower case first if i want to
    //capitalize the names in each part
    p.fixScore();
    counter++;
    vector.add(p); // add person object to vector

    }
    while(counter<10);
    counter=0;
    /* here you should read all you data back from the vector and
    store it in the arrays for sorting and printing
    */

    pp= new person();
    //for(int a=0; a<=9; a++) {
    //pp= (person)vector.get(a);
    //Names[a]=pp.getName();

    //catch(Exception ex){}
    function1(); // remember to pass arrays
    function2(); // remember to pass arrays
    }
    catch(IOException e)
    {System.err.println("File Error:" + e);}
    }

    public void function1( )
    {
    // this function will receive all arrays and compute average, letter grade
    // and sort the arrays based upon average (high to low)
    // You must use a pointer technique -- I will explain
    }

    public void function2( )
    {
    //this function will do all printing
    //for(int a=0; a<=9; a++) {
    //System.out.println(Names[a]);

    }

    public static void main()
    {
    new First_314_Project();
    }
    }


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    646
    My Mood
    Sleepy
    Thanks
    10
    Thanked 95 Times in 88 Posts

    Default Re: Object Orientation Program Help.

    OK, now you've dumped a load of unformatted code that violates coding conventions on us, without even asking a question. What do you expect?

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,373
    My Mood
    Mellow
    Thanks
    254
    Thanked 786 Times in 771 Posts

    Default Re: Object Orientation Program Help.

    Post your code in formatting tags. You can learn how in the Announcments topic at the top of this forum's page.

    I don't know if we can help with "totally lost." Can you focus us on one thing at a time? Point to the first part you don't understand or don't know how to accomplish and ask for help with that. Describe what you don't understand or know how to do and ask specific questions about that topic that will help you.

  4. The Following User Says Thank You to GregBrannon For This Useful Post:

    Coffee_CIS (September 23rd, 2013)

  5. #4
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Object Orientation Program Help.

    I'm sorry. I'm new to this forum. I am not familiar with formatting tags. I am not seeing where the Announcements topic is.

    --- Update ---

    I will create a new thread. Thank you so much.

  6. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Object Orientation Program Help. (Reposted)

    Below are two classes. The person class and the 314 class (object). Embedded in the code are comments that tell you what the professor is asking for. I have already written part of the person class.

    Person class:

    [code=Java]
    // person class

    public class person {
    private String Name;
    private char sex;
    private String score;
    private int[] grades = new int[5];
    private String newName;
    public person() // CONSTRUCTOR
    {

    }
    public void setName(String g) // RECEIVE NAME
    {Name = g; }
    public void setSex(char c) // RECEIVE SEX CODE
    {sex = c;};
    public void setScore(String cat) // RECEIVE SCORES AS STRING
    {score = cat;}
    public void fixName()
    {
    /* HERE IS WHERE YOY TAKE YOUR STRING name
    CONVERT IT TO LOWWER CASE, BREAK IT INTO 2 STRINGS
    (FIRST AND LAST), CONVERT THE FIRST LETTER OF EACH
    PART TO CAPITAL, AND CONCATENATE IT BACK TOGETHER AND
    STORE IT IN newname.
    */


    String last, first;
    first = Name.substring(1, Name.indexOf(" "));
    first = first.toLowerCase();
    first = Name.charAt(0) + first;
    newName = Name.toLowerCase();
    System.out.println(first);
    last = Name.substring(Name.indexOf(" ")+2, Name.length());
    last = last.toLowerCase();
    last = Name.charAt(Name.indexOf(" ")+1) + last;
    newName = Name.toLowerCase();
    System.out.println(last);

    }
    public void fixScore()
    {
    /*HERE YOU TAKE YOUR STRING CALLED scores ABOVE AND USE
    AND STORE IT IN YOUR INTEGER ARRAY CALLED GRADES (ABOVE).
    //10 objects sitting in this method
    //pp=(Person)vector.get(a) where a is 0-9
    */
    String score;
    //

    //grades?

    }
    public String getName() // RETURNS NEWNAME
    {return newName;}
    public char getSex() // RETURNS SEX CODE
    {return sex;}
    //---provide a function that will return the 5 scores for that person.
    //You cannot return an array reference.. find another way.
    }

    [/code/

    314 Class:

     
    import java.io.RandomAccessFile;
    import java.io.EOFException;
    import java.io.IOException;
    import java.util.Vector;
     
    public class First_314_Project
    {
    private RandomAccessFile raf;
    //The entire path to the location of the file
    private final String fileToRead = "DATA314.dat";
    private Vector vector = new Vector();
    private String temp;
    private int c=0;
    private person pp;
    private String[] Names = new String[10];
    private char[] Sex = new char[10];
    private int[][] Score = new int[10][5];
    private float[] averages = new float[5];
    private char[] letter = new char[10];
    public First_314_Project()
    {
    int counter=0;
    try{
    raf = new RandomAccessFile(fileToRead,"r");
    do{
    temp=raf.readUTF(); // raf is an object of the random access file class
    //System.out.println(temp);
    person p = new person();
    int c = temp.indexOf(':');
    String g = temp.substring(0,c);
    char b = temp.charAt(c+1);
    String cat = temp.substring(c+3,temp.length());
    p.setName(g);
    p.setSex(b);
    p.setScore(cat);
    p.fixName();
    //find the blank
    //get the first name
    //get the last name
    //use a substring command and grab position 1 through n-1 grab first name and leave the first letter alone
    // take them apart and concenate them to create the correct order of the names. dont forget to put the comma inbetween the two
    //last name first and then the first name
    //convert the whole thing to lower case first if i want to
    //capitalize the names in each part
    p.fixScore();
    counter++;
    vector.add(p); // add person object to vector
     
    }
    while(counter<10);
    counter=0;
    /* here you should read all you data back from the vector and
    store it in the arrays for sorting and printing
    */
     
    pp= new person();
    //for(int a=0; a<=9; a++) {
    //pp= (person)vector.get(a);
    //Names[a]=pp.getName();
     
    //catch(Exception ex){}
    function1(); // remember to pass arrays
    function2(); // remember to pass arrays
    }
    catch(IOException e)
    {System.err.println("File Error:" + e);}
    }
     
    public void function1( )
    {
    // this function will receive all arrays and compute average, letter grade
    // and sort the arrays based upon average (high to low)
    // You must use a pointer technique -- I will explain
    }
     
    public void function2( )
    {
    //this function will do all printing
    //for(int a=0; a<=9; a++) {
    //System.out.println(Names[a]);
     
    }
     
    public static void main()
    {
    new First_314_Project();
    }
    }

  7. #6
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Object Orientation Program Help.

    Below are two classes. The person class and the 314 class (object). Embedded in the code are comments that tell you what the professor is asking for. I have already written part of the person class.

    Person class:

    // person class
     
    public class person {
    private String Name;
    private char sex;
    private String score;
    private int[] grades = new int[5];
    private String newName;
    public person() // CONSTRUCTOR
    {
     
    }
    public void setName(String g) // RECEIVE NAME
    {Name = g; }
    public void setSex(char c) // RECEIVE SEX CODE
    {sex = c;};
    public void setScore(String cat) // RECEIVE SCORES AS STRING
    {score = cat;}
    public void fixName()
    {
    /* HERE IS WHERE YOY TAKE YOUR STRING name
    CONVERT IT TO LOWWER CASE, BREAK IT INTO 2 STRINGS
    (FIRST AND LAST), CONVERT THE FIRST LETTER OF EACH
    PART TO CAPITAL, AND CONCATENATE IT BACK TOGETHER AND
    STORE IT IN newname.
    */
    // Khan, Emad : M, 100, 98...
    String last, first;
    first = Name.substring(1, Name.indexOf(" "));
    first = first.toLowerCase();
    first = Name.charAt(0) + first;
    newName = Name.toLowerCase();
    System.out.println(first);
    last = Name.substring(Name.indexOf(" ")+2, Name.length());
    last = last.toLowerCase();
    last = Name.charAt(Name.indexOf(" ")+1) + last;
    newName = Name.toLowerCase();
    System.out.println(last);
     
    }
    public void fixScore()
    {
    /*HERE YOU TAKE YOUR STRING CALLED scores ABOVE AND USE
    AND STORE IT IN YOUR INTEGER ARRAY CALLED GRADES (ABOVE).
    //10 objects sitting in this method
    //pp=(Person)vector.get(a) where a is 0-9
    */
    String score;
    //
     
    //grades?
     
    }
    public String getName() // RETURNS NEWNAME
    {return newName;}
    public char getSex() // RETURNS SEX CODE
    {return sex;}
    //---provide a function that will return the 5 scores for that person.
    //You cannot return an array reference.. find another way.
    }


    314 Class:

    import java.io.RandomAccessFile;
    import java.io.EOFException;
    import java.io.IOException;
    import java.util.Vector;
     
    public class First_314_Project
    {
    private RandomAccessFile raf;
    //The entire path to the location of the file
    private final String fileToRead = "DATA314.dat";
    private Vector vector = new Vector();
    private String temp;
    private int c=0;
    private person pp;
    private String[] Names = new String[10];
    private char[] Sex = new char[10];
    private int[][] Score = new int[10][5];
    private float[] averages = new float[5];
    private char[] letter = new char[10];
    public First_314_Project()
    {
    int counter=0;
    try{
    raf = new RandomAccessFile(fileToRead,"r");
    do{
    temp=raf.readUTF(); // raf is an object of the random access file class
    //System.out.println(temp);
    person p = new person();
    int c = temp.indexOf(':');
    String g = temp.substring(0,c);
    char b = temp.charAt(c+1);
    String cat = temp.substring(c+3,temp.length());
    p.setName(g);
    p.setSex(b);
    p.setScore(cat);
    p.fixName();
    //find the blank
    //get the first name
    //get the last name
    //use a substring command and grab position 1 through n-1 grab first name and leave the first letter alone
    // take them apart and concenate them to create the correct order of the names. dont forget to put the comma inbetween the two
    //last name first and then the first name
    //convert the whole thing to lower case first if i want to
    //capitalize the names in each part
    p.fixScore();
    counter++;
    vector.add(p); // add person object to vector
     
    }
    while(counter<10);
    counter=0;
    /* here you should read all you data back from the vector and
    store it in the arrays for sorting and printing
    */
     
    pp= new person();
    //for(int a=0; a<=9; a++) {
    //pp= (person)vector.get(a);
    //Names[a]=pp.getName();
     
    //catch(Exception ex){}
    function1(); // remember to pass arrays
    function2(); // remember to pass arrays
    }
    catch(IOException e)
    {System.err.println("File Error:" + e);}
    }
     
    public void function1( )
    {
    // this function will receive all arrays and compute average, letter grade
    // and sort the arrays based upon average (high to low)
    // You must use a pointer technique -- I will explain
    }
     
    public void function2( )
    {
    //this function will do all printing
    //for(int a=0; a<=9; a++) {
    //System.out.println(Names[a]);
     
    }
     
    public static void main()
    {
    new First_314_Project();
    }
    }


    --- Update ---

    Here is one part I am not sure how to code.
    public void fixScore()
    {
    /*HERE YOU TAKE YOUR STRING CALLED scores ABOVE AND USE
    AND STORE IT IN YOUR INTEGER ARRAY CALLED GRADES (ABOVE).
    //10 objects sitting in this method
    //pp=(Person)vector.get(a) where a is 0-9
    */
    String score;

  8. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Object Orientation Program Help.

    Duplicate threads merged

  9. The Following User Says Thank You to jps For This Useful Post:

    Coffee_CIS (September 23rd, 2013)

  10. #8
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    646
    My Mood
    Sleepy
    Thanks
    10
    Thanked 95 Times in 88 Posts

    Default Re: Object Orientation Program Help.

    OK, so you have a String scores = "12345" or similar. Each digit has to be stored at an index of the array grades.
    you can loop over the String and use charAt() or substring() to get the single digits. Integer has quite a few methods to convert other datatypes into an int. As you are already looping, you can assign that new int to an index of the array.

Similar Threads

  1. Create the object of that program i'll pay for him/her
    By umerabidin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 15th, 2013, 06:56 AM
  2. object oriented program help!!!
    By Username in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 16th, 2013, 08:15 AM
  3. How do I delete an object from my program?
    By Skynet928 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 19th, 2013, 08:13 PM
  4. NEED HELP TO FIX Object oriented Program Facebook
    By Ryo in forum Object Oriented Programming
    Replies: 15
    Last Post: February 29th, 2012, 10:04 AM
  5. Object Oriented program, no output
    By boardbreaker in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 17th, 2009, 11:11 PM

Tags for this Thread