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));
Topic: Java programming language I have two parent class called Student and Unit. Both of them have two subclasses e.g:
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am