Question
********* JAVA HELP ************* i need help to modify this code becuase when I ran the program I got two errors ( Students.java:10: error: class,
********* JAVA HELP *************
i need help to modify this code becuase when I ran the program I got two errors
( Students.java:10: error: class, interface, or enum expected Student.java ^ Students.java:82: error: class, interface, or enum expected StudentTest.java ^ 2 errors)
Also, I'd like to start my code with
public class Student {
public static void main(String[] args) {
Just make it look simple to me, so in case later if i need to modefiy I can edit it by my self & understand better i'm just a beginner
here is the code
________________________________________________
Student.java
public class Student
{
//attributes
private int id;
private String name;
//default constructor
public Student()
{
id=0;
name="";
}
//parameterized constructor
public Student(int id, String name) {
super();
this.id = id;
this.name = name;
}
//setters and gettes
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + "]";
}
}
StudentTest.java
public class StudentTest
{
public static void main(String args[])
{
Student student[] = new Student[5];//array of student objects
//creating and adding objects to array
student[0]=new Student(3,"Mohammad");
student[1]=new Student(5,"Lynda");
student[2]=new Student(4,"Ashun");
student[3]=new Student(2,"Lydia");
student[4]=new Student(1,"Marbella");
//printing array in sorted order
System.out.println("Students in unsorted order:");
for(int i=0;i System.out.println(student[i].toString()); //using bubble sort to sort the student objects in sorted order for(int i=0;i { for(int j=0;j { if(student[j].getId()>student[j+1].getId()) { Student temp=student[j]; student[j]=student[j+1]; student[j+1]=temp; } } } //printing array in sorted order System.out.println("Students in sorted order:"); for(int i=0;i System.out.println(student[i].toString()); } public void doStuff(int n) { if (n try { throw new Exception("Negative number."); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } __________________ the output should be like
Step 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