How can I add the units he/she enrolled every time the user inputs the code he/she wants to enroll? Is there any way I can add the units every time he/she enroll using arrayList?
int units = 3
arrList.add("A25"+"\t\tCS 212"+"\t\tData Structures\t\t\t\t"+ units);
arrList.add("A26"+"\t\tIT 312"+"\t\tData Base Management System 2\t\t"+ units);
arrList.add("A27"+"\t\tIT 312"+"\t\tData Base Management System 2\t\t"+ units);
System.out.println("\n\t\tCodes to enroll");
for(int i = 0; i < 3; i++,num++)
{
codeNo[i] = scan.next();
}
for (String s : arrList) {
for(int i =0; i < codeNo.length; i++)
if (s.startsWith(codeNo[i])) {
System.out.println("\t\t\t"+s);
/**
* this is what I tried
* units = units + units;
*/
}
}
tuitionFee = ( tuitionFee * units + miscFee ) / 3;
System.out.println("\n\n\t\tTOTAL FEE: ");
System.out.printf("\t\tPrelims: "+"%.2f",tuitionFee);
System.out.printf("\t\tMidTerm: "+"%.2f",tuitionFee);
System.out.printf("\t\tFinals: "+"%.2f",tuitionFee);
HashMap<String,Integer> mapCodeToUnit = new HashMap<String,Integer>();
mapCodeToUnit.put("A25", 3);
mapCodeToUnit.put("A26", 3);
mapCodeToUnit.put("A27", 3);
arrList.add("A25"+"\t\tCS 212"+"\t\tData Structures\t\t\t\t"+ mapCodeToUnit.get("A25"));
arrList.add("A26"+"\t\tIT 312"+"\t\tData Base Management System 2\t\t"+ mapCodeToUnit.get("A26"));
arrList.add("A27"+"\t\tIT 312"+"\t\tData Base Management System 2\t\t"+ mapCodeToUnit.get("A27"));
System.out.println("\n\t\tCodes to enroll");
String codeNo[] = new String[3];
for(int i = 0; i < 3; i++,num++)
{
codeNo[i] = scan.next();
}
int totalNumberOfUnit = 0;
for(int i =0; i < codeNo.length; i++) {
totalNumberOfUnit += mapCodeToUnit.get(codeNo[i]);
}
tuitionFee = ( tuitionFee * totalNumberOfUnit + miscFee ) / 3;
Make a list of EntrollmentDTO
instead of list of String
EntrollmentDTO.java
class EntrollmentDTO {
private String id;
private String subId;
private String subName;
// Getters & Setters
}
Make a List of EntrollmentDTO
as,
ArrayList<EntrollmentDTO> entrollmentList = new ArrayList<EntrollmentDTO>();
And add details as,
EntrollmentDTO entrollmentDTO = new EntrollmentDTO();
entrollmentDTO.setId("A25");
// set all values
entrollmentList.add(entrollmentDTO);
By this you can easily access needed values from the list.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.