Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java: 2.) Modify 1.) from above. Add a new Method called selectDB() that takes only one argument, SID. When a user calls this method,

Using Java:

2.) Modify 1.) from above. Add a new Method called selectDB() that takes only one argument, SID. When a user calls this method, it should SELECT from the database that Student and get all the Students data from the database, and put this data into the appropriate properties. (Hint: You will use an SQL Select statement here.) Test out this method in the main.

Testing Code in Main() method

Student s1 = new Student();

s1.selectDB(4); //accessing DB

s1.display(); //displays all data from DB for student with id=4

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

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();

}

}

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 75213

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

Give a brief defi ni tion of the terms population and sample.

Answered: 1 week ago