Using Java 1.) Create a class called Student. This class will not be tied to the
ID: 3735394 • Letter: U
Question
Using Java
1.) Create a class called Student. This class will not be tied to the Database, yet. The Student class should have the same properties as the Database table: SID, FirstName, LastName, etc. Include all the set and get functions as needed. Include 2 constructors, an empty constructor, and one that takes all properties. Include a display() method that prints out all properties. Use a main to instantiate and test out this Student class. (Hint: No database calls in this class, yet.)
Testing Code in Main() method à
Student s1 = new Student(4,”Frank”, “Jones”, “123 Main”, “Atlanta”, “GA”, 30133, “fj@yahoo.com”, 3.2);
s1.display();
Students ID FirstName LastName Street City State Zip EMail GPA 1 Larry Jones 200 Larue St. Denver CO 89721 larry@yahoo.com 3.2 2 Debbie Gibson 101 Cambell St. Chicago IL 61721 debra@hotmail.com 2.9 3 James Henry 9019 Par Ln. Atlanta GA 30981 jh@yahoo.com 3.5 4 Tony Danza 100 Main St San Diego CA 90890 tony@yahoo.com 3.4 5 Marie Baker 313 Mockingbid Lane Seattle WA 98711 mbaker@hotmail.com 2.2 6 Mary Weathers 10 King St Denver CO 65334 maryw@bellsouth.net 2.1 7 Biily Wagner 777 Blake St Chicago IL 61900 billyw@comcast.net 2.9 8 Tim Allen 200 South St Detroit MI 54123 9 Gary Stevens 112 Plymouth Ln Ann Arbor MI 54123 garys@hotmail.com 3.2 10 Betsy Cook 101 Freeport St Atlanta GA 31010 bcook@yahoo.com 3.3 11 Susan Jones 200 West Ave Marietta GA 30060 sujones@hotmail.com 2.2 12 Frank Peters 3845 Beckford Ave San Diego CA 95123 frankperters@comcast.net 3.9 13 Terri March 9516 Hale Dr St Louis MO 63321 tmarch@bellsouth.net 3.1 14 Jack Hines 2222 Morningside Dr Marietta GA 30090 jhines@yahoo.com 2.8 15 Phil Gecko 45 East St Montgomery AL 41231 pgecko@yahoo.com 2.7 16 Tony Peters 200 Central Ave Miami FL 75213Explanation / Answer
i write the code for you as per the instructions.as it is always suggested that create bean class and class containing main different. i did this. and also done this thing in single class also. so use which one you like.
note :- first student class contains all the things you need in one class.
after that there are two classes if you want your code to be in professional way . first is Student.java other is Main.java
-------------------
name this class as Student .java.
public class Student {
private int id;
private String firstName;
private String street;
private String city;
private String state;
private String zip;
private String email;
double gpa;
private String lastName;
public Student(int id, String firstName, String lastName, String street, String city, String state, String zip,
String email, double gpa) {
super();
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
this.email = email;
this.gpa = gpa;
}
public Student() {
super();
}
public void display() {
System.out.println("ID "+getId()+" First Name "+getFirstName()+" Last Name "+getLastName()+ " Email "+getEmail()+" City "+getCity()+" Street "+getStreet()+" State "+getState()+" Zip "+getZip()+" GPA "+getGpa());
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public static void main(String args[]) {
Student s1 = new Student(1, "rahul", "chopra", "1 india", "nxyz", "abcz", "1313", "abcz@abcz.com", 3.2);
Student s2 = new Student(2, "firstName", "lastName", "street", "city", "state", "zip", "email", 3.2);
s1.display();
}
}
-------------------------------------
another way of doing by having two seperate classes
Main.java
public class Main {
public static void main(String args[]) {
Student s1 = new Student(1, "rahul", "chopra", "1 india", "nxyz", "abcz", "1313", "abcz@abcz.com", 3.2);
Student s2 = new Student(2, "firstName", "lastName", "street", "city", "state", "zip", "email", 3.2);
s1.display();
}
}
=================================
//Student.java
package sads;
public class Student {
private int id;
private String firstName;
private String street;
private String city;
private String state;
private String zip;
private String email;
double gpa;
private String lastName;
public Student(int id, String firstName, String lastName, String street, String city, String state, String zip,
String email, double gpa) {
super();
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
this.email = email;
this.gpa = gpa;
}
public Student() {
super();
}
public void display() {
System.out.println("ID "+getId()+" First Name "+getFirstName()+" Last Name "+getLastName()+ " Email "+getEmail()+" City "+getCity()+" Street "+getStreet()+" State "+getState()+" Zip "+getZip()+" GPA "+getGpa());
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.