Question
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
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 objectStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started