Results 1 to 4 of 4
  1. #1
    carmania24's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    15
    Reputation
    10
    Thanks
    1

    Beginner in Java- Need Help With Project

    Hi everyone!

    First- thank you for taking a look at this forum, any help is greatly appreciated.

    Here is what the instructions say:

    Create a Java NetBeans project named StudentClient with the main class named StudentClient. Add a service class to the project named Student. This program will encapsulate the concept of a student, assuming a student has the following attributes (instance variables): a name, a social security number and a GPA (e.g., 3.5).For the Student class you will write the constructors, accessors and mutators, and toString and equals methods. In the client application class you will instantiate student class objects and write statements (method calls) to test the methods in your student service class.

    I have 0 ideas on how to start this, and this is my biggest project (grade wise), so if you have any idea on how I can start it I will love you forever (no homo)

    PS: I have another project in which I will upload the code to pastebin, I want to make sure I did that properly or not, and I will post a link back here along with the instructions in pastebin

  2. #2
    Cosmo_'s Avatar
    Join Date
    Oct 2014
    Gender
    male
    Location
    Los Angeles
    Posts
    126
    Reputation
    13
    Thanks
    19
    My Mood
    Sleepy
    This is what I came up with. If you need me to explain anything feel free to message me.

    Code:
    public class StudentClient {
    
        public static void main(String[] args) {
    	Student mark = new Student("Mark", 555555555, 3.6);
            System.out.println(mark.toString());
    
            Student leslie = new Student();
            leslie.equals(mark);
            leslie.setName("Leslie");
            System.out.println(leslie.toString());
        }
    }
    Code:
    public class Student {
    
        private String name;
        private int socialSecurityNumber;
        private double gpa; // grade point average
    
        private static final String DEFAULT_NAME = "Unregistered";
        private static final int DEFAULT_SOCIAL_SECURITY_NUMBER = 111111111;
        private static final int HIGHEST_SOCIAL_SECURITY_NUMBER = 999999999;
        private static final double LOWEST_GPA = 0.0;
        private static final double HIGHEST_GPA = 4.0;
    
        public String toString() {
            String information = "Name: " + name;
            information += "\n" + "Social Security Number: " + socialSecurityNumber;
            information += "\n" + "G.P.A: " + gpa;
    
            return information;
        }
    
        public void equals(Student student) {
            this.name = student.getName();
            this.socialSecurityNumber = student.getSocialSecurityNumber();
            this.gpa = student.getGpa();
        }
    
        // ================================== CONSTRUCTORS =========================================== //
    
        public Student() {
            this(DEFAULT_NAME, DEFAULT_SOCIAL_SECURITY_NUMBER, LOWEST_GPA);
        }
    
        public Student(String name) {
            this(name, DEFAULT_SOCIAL_SECURITY_NUMBER, LOWEST_GPA);
        }
    
        public Student(int socialSecurityNumber) {
            this(DEFAULT_NAME, socialSecurityNumber, LOWEST_GPA);
        }
    
        public Student(double gpa) {
            this(DEFAULT_NAME, DEFAULT_SOCIAL_SECURITY_NUMBER, gpa);
        }
    
        public Student(String name, int socialSecurityNumber) {
            this(name, socialSecurityNumber, LOWEST_GPA);
        }
    
        public Student(String name, double gpa) {
            this(name, DEFAULT_SOCIAL_SECURITY_NUMBER, gpa);
        }
    
        public Student(int socialSecurityNumber, double gpa) {
            this(DEFAULT_NAME, socialSecurityNumber, gpa);
        }
    
        public Student(String name, int socialSecurityNumber, double gpa) {
    
            // check to see if blank string was passed as the name
            // if it was then set name to default value otherwise set this.name = to string passed
            if (name.equals("")) {
                this.name = DEFAULT_NAME;
            }else {
                this.name = name;
            }
    
            // check that social is between 0 and 999999999
            // if not set it equal to default value
            if (socialSecurityNumber >= DEFAULT_SOCIAL_SECURITY_NUMBER && socialSecurityNumber <= HIGHEST_SOCIAL_SECURITY_NUMBER) {
                this.socialSecurityNumber = socialSecurityNumber;
            } else {
                this.socialSecurityNumber = DEFAULT_SOCIAL_SECURITY_NUMBER;
            }
    
            // ensure that the gpa passed to the method is between 0.0 and 4.0 inclusive
            // else set it equal to lowest value
            if (gpa >= LOWEST_GPA && gpa <= HIGHEST_GPA) {
                this.gpa = gpa;
            } else {
                this.gpa = LOWEST_GPA;
            }
        }
    
        // ============================ Getter and Setters ===================================== //
    
        public String getName() {
            return this.name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getSocialSecurityNumber() {
            return this.socialSecurityNumber;
        }
    
        public void setSocialSecurityNumber(int socialSecurityNumber) {
            this.socialSecurityNumber = socialSecurityNumber;
        }
    
        public double getGpa() {
            return this.gpa;
        }
    
        public void setGpa(double gpa) {
            this.gpa = gpa;
        }
    }
    - - - Updated - - -

    Here was the output from the code above:

    Name: Mark
    Social Security Number: 555555555
    G.P.A: 3.6
    Name: Leslie
    Social Security Number: 555555555
    G.P.A: 3.6

    Process finished with exit code 0

  3. #3
    carmania24's Avatar
    Join Date
    Oct 2015
    Gender
    male
    Posts
    15
    Reputation
    10
    Thanks
    1
    Quote Originally Posted by Cosmo_ View Post
    This is what I came up with. If you need me to explain anything feel free to message me.

    Code:
    public class StudentClient {
    
        public static void main(String[] args) {
    	Student mark = new Student("Mark", 555555555, 3.6);
            System.out.println(mark.toString());
    
            Student leslie = new Student();
            leslie.equals(mark);
            leslie.setName("Leslie");
            System.out.println(leslie.toString());
        }
    }
    Code:
    public class Student {
    
        private String name;
        private int socialSecurityNumber;
        private double gpa; // grade point average
    
        private static final String DEFAULT_NAME = "Unregistered";
        private static final int DEFAULT_SOCIAL_SECURITY_NUMBER = 111111111;
        private static final int HIGHEST_SOCIAL_SECURITY_NUMBER = 999999999;
        private static final double LOWEST_GPA = 0.0;
        private static final double HIGHEST_GPA = 4.0;
    
        public String toString() {
            String information = "Name: " + name;
            information += "\n" + "Social Security Number: " + socialSecurityNumber;
            information += "\n" + "G.P.A: " + gpa;
    
            return information;
        }
    
        public void equals(Student student) {
            this.name = student.getName();
            this.socialSecurityNumber = student.getSocialSecurityNumber();
            this.gpa = student.getGpa();
        }
    
        // ================================== CONSTRUCTORS =========================================== //
    
        public Student() {
            this(DEFAULT_NAME, DEFAULT_SOCIAL_SECURITY_NUMBER, LOWEST_GPA);
        }
    
        public Student(String name) {
            this(name, DEFAULT_SOCIAL_SECURITY_NUMBER, LOWEST_GPA);
        }
    
        public Student(int socialSecurityNumber) {
            this(DEFAULT_NAME, socialSecurityNumber, LOWEST_GPA);
        }
    
        public Student(double gpa) {
            this(DEFAULT_NAME, DEFAULT_SOCIAL_SECURITY_NUMBER, gpa);
        }
    
        public Student(String name, int socialSecurityNumber) {
            this(name, socialSecurityNumber, LOWEST_GPA);
        }
    
        public Student(String name, double gpa) {
            this(name, DEFAULT_SOCIAL_SECURITY_NUMBER, gpa);
        }
    
        public Student(int socialSecurityNumber, double gpa) {
            this(DEFAULT_NAME, socialSecurityNumber, gpa);
        }
    
        public Student(String name, int socialSecurityNumber, double gpa) {
    
            // check to see if blank string was passed as the name
            // if it was then set name to default value otherwise set this.name = to string passed
            if (name.equals("")) {
                this.name = DEFAULT_NAME;
            }else {
                this.name = name;
            }
    
            // check that social is between 0 and 999999999
            // if not set it equal to default value
            if (socialSecurityNumber >= DEFAULT_SOCIAL_SECURITY_NUMBER && socialSecurityNumber <= HIGHEST_SOCIAL_SECURITY_NUMBER) {
                this.socialSecurityNumber = socialSecurityNumber;
            } else {
                this.socialSecurityNumber = DEFAULT_SOCIAL_SECURITY_NUMBER;
            }
    
            // ensure that the gpa passed to the method is between 0.0 and 4.0 inclusive
            // else set it equal to lowest value
            if (gpa >= LOWEST_GPA && gpa <= HIGHEST_GPA) {
                this.gpa = gpa;
            } else {
                this.gpa = LOWEST_GPA;
            }
        }
    
        // ============================ Getter and Setters ===================================== //
    
        public String getName() {
            return this.name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getSocialSecurityNumber() {
            return this.socialSecurityNumber;
        }
    
        public void setSocialSecurityNumber(int socialSecurityNumber) {
            this.socialSecurityNumber = socialSecurityNumber;
        }
    
        public double getGpa() {
            return this.gpa;
        }
    
        public void setGpa(double gpa) {
            this.gpa = gpa;
        }
    }
    - - - Updated - - -

    Here was the output from the code above:

    Name: Mark
    Social Security Number: 555555555
    G.P.A: 3.6
    Name: Leslie
    Social Security Number: 555555555
    G.P.A: 3.6

    Process finished with exit code 0
    Wow I can't thank you enough!! I will try the code out once I get home. )

    Btw nice user name my dogs name is also Cosmo :P

  4. #4
    Cosmo_'s Avatar
    Join Date
    Oct 2014
    Gender
    male
    Location
    Los Angeles
    Posts
    126
    Reputation
    13
    Thanks
    19
    My Mood
    Sleepy
    No problem and good luck!

Similar Threads

  1. [Solved] I need help with Project blackout :S
    By takinardy in forum Piercing Blow Help
    Replies: 8
    Last Post: 08-16-2012, 04:54 AM
  2. [Solved] need help with java
    By abonabel in forum CrossFire Help
    Replies: 5
    Last Post: 08-03-2011, 02:17 PM
  3. I need help with this project
    By killer121561 in forum Combat Arms Coding Help & Discussion
    Replies: 7
    Last Post: 08-02-2011, 07:42 PM
  4. Need help with starting a HUGE project (this goes for AZUMKILL, CrazyApple, IZ3RO etc
    By lior19940 in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 20
    Last Post: 09-13-2010, 05:20 AM
  5. Need help with a personal project: Hacking NavyField
    By Slinky in forum Hack Requests
    Replies: 19
    Last Post: 10-23-2006, 01:23 PM