Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 6 CS210.03 Spring 2017 Due Monday April 24th @ 7pm Assignment 6 consi

ID: 3826223 • Letter: A

Question

Assignment 6

CS210.03

Spring 2017

Due Monday April 24th @ 7pm

Assignment 6 consists of practicing creating classes and using objects. You are required to create two new classes: “Student” and “Date.” These two classes will have the following fields: Student:

-String name

-int id

-Date birthdate Date:

-int month

-int day

-int year

Both classes will have a constructor that takes arguments to set the intial values for each of their fields. Both classes will have a method titled “toString” that returns a String in the following format:

Student.toString() returns:

<name>:

Birthdate: <birthday.toString()> Student ID: <id>

Date.toString() returns:

<month>/<day>/<year>

Write a simple main method in your public class that creates a new student object and prints the object in the correct format.

Sample output is as follows:

~/Desktop » java A6 tyler

Student ID: 1001

Birthdate: 9/23/1994

~/Desktop »

Deliverables:

You may work in groups of two for this project. Submit a compressed (.zip) folder to the iLearn submission link for assignment 2. The folder will contain two files: your java code, and a writeup, in PDF format, stating what you did, who (if anyone) your partner was, any difficulty you had, and what you learned.

Explanation / Answer

Please find the below code and output. I explained clearly.

Student.java

public class Student {

            String name;

            int id;

            Date birthDate;

            public Student(String name, int id, Date birthDate) {

                        super();

                        this.name = name;

                        this.id = id;

                        this.birthDate = birthDate;

            }

            @Override

            public String toString() {

                        return "Name: " + name + ", Student ID=" + id + ", BirthDate: " + birthDate ;

            }

}

Date.java

public class Date {

            int month;

            int day;

            int year;

            public Date(int month, int day, int year) {

                        super();

                        this.month = month;

                        this.day = day;

                        this.year = year;

            }

            @Override

            public String toString() {

                        return month +"/"+ day +"/"+ year;

            }

}

Assignment6.java (Main class)

public class Assignment6 {

            public static void main(String[] args){

                        Date d = new Date(04, 28, 1993);

                        Student s = new Student("bags", 1 ,d);

                        System.out.println(s.toString());

            }

}

OUTPUT

Name: bags, Student ID=1, BirthDate: 4/28/1993