Hi, I have this piece of code, which adds marks into 2 different arrayLists, one for homework marks, and one for examination marks..
ArrayList<Double> homeworkMark = new ArrayList<Double>(); ArrayList<Double> examinationMark = new ArrayList<Double>(); boolean markCheck = true; do{ //the purpose of this try catch is to make sure that the entered mark is a valid number. If the program encounters an exception markCheck will become true and the loop will begin again asking the user to enter the marks. If the marks are all encountered correctly markCheck will be false and the loop will end. try{ for (int i = 1; i <= amountAssignment; i++ ) { sc.reset(); System.out.print("Homework Mark for Assignment " +(i) + ": "); homeworkMark.add(sc.nextDouble()); System.out.print("Examination Mark for Assignment " + (i) + ": "); examinationMark.add(sc.nextDouble()); markCheck = false; } }catch (Exception e) { e.printStackTrace(); System.out.println("------------"); System.out.println("| ERROR |"); System.out.println("------------"); System.out.println("You'll have to enter your marks again!") ; System.out.println(""); markCheck = true; } }while (markCheck == true);
I need to add the data from this arrayList in the Main method into an arrayList in a different class, named subject, which can found below...
import java.util.ArrayList; public class subject { int subjectNumber; public subject(int subjectNumber) { this.subjectNumber = subjectNumber; } public int getSubjectNumber() { return subjectNumber; } void setSubjectNumber (int subNum) { subjectNumber= subNum; } }
I have no idea how to do this and I've tried multiple things but cannot seem to get anywhere... :-(
Regards