Topic: Java programming language I have two parent class called Student and Unit. Both of them have two subclasses e.g:

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Topic: Java programming language I have two parent class called Student and Unit. Both of them have two subclasses e.g:

Post by answerhappygod »

Topic: Java programming language
I have two parent class called Student and Unit. Both of them
have two subclasses e.g: Student_Common, Student_Major for
Students and Unit_Common, Unit_Major for Units.
In the client class I need to add Unit_Common/Major details to
Arraylist <Student> students but I am not sure on how to add
it as it says no suitable method found for add
(Unit_Common)
Example code is here:
public void addArrayList(ArrayList<Student>
students)
{
//scanner object
Scanner readUnit = null;
//try block
try{
String infilename;
//asks for file
name
System.out.println("Enter
file name: ");
infilename =
input.nextLine();
//Scanner in = new
Scanner(new File("UnitInfo.txt"));

while(readUnit.hasNextLine())
{

String
common = readUnit.nextLine();
String[]
parts = common.split(" ");
String
enroltype = parts[0];
String
unitID = parts[1];
int
unitLevel = Integer.parseInt(parts[2]);
Double
assign1 = Double.parseDouble(parts[3]);
Double
assign2 = Double.parseDouble(parts[4]);
Double
weeklyPrac = Double.parseDouble(parts[5]);
Double
finalExam = Double.parseDouble(parts[6]);

students.add(new
Unit_Common(enroltype,unitID,unitLevel,assign1,assign2,weeklyPrac,finalExam));
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply