Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

so this is to file one of them called student.java another one called studentdemo.java i have already wrote the following code. Just edit it and

image text in transcribedimage text in transcribed

so this is to file one of them called student.java

another one called studentdemo.java

i have already wrote the following code. Just edit it and make it works it will be good to me! thanks! And add comments please!

public class Student { //attributes private String name; private String id; private int startYr; private int gradYr; //constructor public Student(String name,String id,int startYr,int gradYr) { this.name=name; this.id=id; this.startYr=startYr; this.gradYr=gradYr; } public void setname(String n) { name=n; } public void setid(String i) { id=i; } public void setstartYr(int st) { startYr=st; } public void setgradYr(int gr) { gradYr=gr; } public String getname() { return name; } public String getid() { return id; } public int getstartYr() { return startYr; } public int getgradYr() { return gradYr; } public String toString() { return "name:"+name+"id: "+id; } }

////////////////////////////////////

import java.util.*; public class StudentDemo{ public static void main(String []args) { Scanner kb=new Scanner(System.in); String name,id; int startYr,gradYr; name=kb.next(); id=kb.next(); startYr=kb.nextInt(); gradYr=kb.nextInt(); Student a=new Student(name,id,startYr,gradYr); a.Student(name,id,startYr,gradYr); a.Student.setname(name); } }

Implement a Student class that has the following private attributes: name (String) . id (String) startYr (int) gradYr (int) and the following methods: Constructor (that sets the name, id, startYr, gradYr from defined values) .Get and set methods toString() method returns the name and ID of the student Then create a StudentDemo class to create and use Student objects. The StudentDemo class contains the main method. Use a Scanner object to read the attributes for a Student object. Create a Student object by passing in the attributes read in by the Scanner object

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

Students also viewed these Databases questions