I have been working on this assignment all day. And I still not able to get the
ID: 3727770 • Letter: I
Question
I have been working on this assignment all day. And I still not able to get the problem to run:
Defining Java classes is one of two steps we practice when using objects. The second step is to instantiate Java classes into objects and to use these objects in our application.
In this discussion, you will practice instantiating an already defined Java class into objects and invoking the attributes of these objects.
You can use either the Toolwire environment or your local Java development environment to complete the coding for this discussion.
Unzip the attached NetBeans project zip file (U10D1_InstantiateUseArrayOfObjects.zip) and load it into your NetBeans IDE.
The project defines two classes:
A Java class called Course (in Course.java) with certain attributes, and
Another class called U10D1_InstantiateUseArrayOfObjects (in U10D1_InstantiateUseArrayOfObjects.java). This class creates an array of Course objects and initializes their attributes to specific values and then calls the WriteCurrentRegistration() to print the current list of registered classes and their total credit hours. The WriteCurrentRegistration() still needs to be coded.
Code the WriteCurrentRegistration() method to meet the stated requirements specified in the project
package u10d1_instantiateusearrayofobjects;
/**
*
*
*/
public class U10D1_InstantiateUseArrayOfObjects {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Course[] courses = {
new Course("IT1006", 6, false),
new Course("IT4782", 3, false),
new Course("IT4789", 3, false),
new Course("IT4079", 6, false),
new Course("IT2230", 3, true),
new Course("IT3345", 3, true),
new Course("IT2249", 6, false)
};
WriteCurrentRegistration(courses);
}
//This method prints the current list of registered courses thus far
//from the courses array separated by , and enclosed inside { }
//It also prints the total credit registered for thus far
public static void WriteCurrentRegistration(Course[] courses) {
//TODO:
//loop over the courses array and print
//the current list of registered courses
//separated by , and enclosed inside { }
//Also, print the total credit registered for
}
}
Explanation / Answer
package u10d1_instantiateusearrayofobjects;
/**
*
*
*/
public class U10D1_InstantiateUseArrayOfObjects {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Course[] courses = {
new Course("IT1006", 6, false),
new Course("IT4782", 3, false),
new Course("IT4789", 3, false),
new Course("IT4079", 6, false),
new Course("IT2230", 3, true),
new Course("IT3345", 3, true),
new Course("IT2249", 6, false)
};
WriteCurrentRegistration(courses);
}
//This method prints the current list of registered courses thus far
//from the courses array separated by , and enclosed inside { }
//It also prints the total credit registered for thus far
public static void WriteCurrentRegistration(Course[] courses) {
//TODO:
//loop over the courses array and print
//the current list of registered courses
//separated by , and enclosed inside { }
//Also, print the total credit registered for
int total = 0;
for(int i = 0;i<courses.length;++i){
System.out.println(courses[i].getName() + " " + courses[i].getCredit() );
total = total + courses[i].getCredit();
}
System.out.println("Student registered for Total Credit: "+ total);
}
}
==============
Seince you did not provide Courses.java, I am expecting Courses.java has the function getCredit() and .getName()
If Not you can change the name , It should work. I have calculated total Credit as well.
Thanks, LET ME KNOW IF THERE Is any concern. Comment and I will respond
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.