Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

********* 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

image text in transcribed

StudentTest [Java Application] C:\F Students in unsorted order: Student [id-3, name-jhon] Student [id-5, name-Abraham] Student [id-4, name-Denny] Student [id-2, name-Lilly] Student [id-1, name Adam] Students in sorted order: Student [id-1, name Adam] Student [id-2, name-Lilly] Student [id-3, name-jhon] Student [id-4, name-Denny] Student [id-5, name-Abraham]

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

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

Understand the purpose and methods of cross-cultural training

Answered: 1 week ago