Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Name: KANU IFEANYI EMMANUEL

Mat No.:COS/5543/2019
Course:CSC413

Java:

import java.util.*;

class Student {
String name;
String matNo;
String gender;
String department;
String dob;
int level;
int schoolFees;
int sugFee;
int deptDues;

public Student(String name, String matNo, String gender, String department, String dob, int
level, int schoolFees, int sugFee, int deptDues) {
this.name = name;
this.matNo = matNo;
this.gender = gender;
this.department = department;
this.dob = dob;
this.level = level;
this.schoolFees = schoolFees;
this.sugFee = sugFee;
this.deptDues = deptDues;
}

public int computeTotalFees() {


return schoolFees + sugFee + deptDues;
}
}

public class Main {


public static void main(String[] args) {
List<Student> students = new ArrayList<>();
students.add(new Student("John Doe", "CS1001", "Male", "Computer Science", "2000-01-
01", 100, 100000, 5000, 2000));
// Add more students here
Map<Integer, List<Student>> studentsByLevel = new HashMap<>();
for (Student student : students) {
if (studentsByLevel.containsKey(student.level)) {
studentsByLevel.get(student.level).add(student);
} else {
List<Student> levelStudents = new ArrayList<>();
levelStudents.add(student);
studentsByLevel.put(student.level, levelStudents);
}
}

for (Map.Entry<Integer, List<Student>> entry : studentsByLevel.entrySet()) {


int level = entry.getKey();
System.out.println("Students in level " + level + ":");
for (Student student : entry.getValue()) {
int totalFees = student.computeTotalFees();
System.out.println(student.name + " - Total Fees: " + totalFees);
}
}
}
}

JavaScript:

class Student {
constructor(name, matNo, gender, department, dob, level, schoolFees, sugFee, deptDues) {
this.name = name;
this.matNo = matNo;
this.gender = gender;
this.department = department;
this.dob = dob;
this.level = level;
this.schoolFees = schoolFees;
this.sugFee = sugFee;
this.deptDues = deptDues;
}

computeTotalFees() {
return this.schoolFees + this.sugFee + this.deptDues;
}
}

const students = [
new Student("John Doe", "CS1001", "Male", "Computer Science", "2000-01-01", 100,
100000, 5000, 2000),
// Add more students here
];

const studentsByLevel = students.reduce((acc, student) => {


acc[student.level] = acc[student.level] || [];
acc[student.level].push(student);
return acc;
}, {});

for (const level in studentsByLevel) {


console.log(`Students in level ${level}:`);
studentsByLevel[level].forEach(student => {
const totalFees = student.computeTotalFees();
console.log(`${student.name} - Total Fees: ${totalFees}`);
});
}

Comparison:

Syntax: Java and JavaScript have different syntaxes. Java is a statically typed language with a
syntax resembling C++, while JavaScript is dynamically typed and has a syntax similar to C.

Type System: Java is statically typed, meaning variables must be declared with their types at
compile time, while JavaScript is dynamically typed, allowing variables to hold values of any
type without explicit declaration.

Platform: Java is often used for building server-side applications, Android apps, and enterprise
systems, while JavaScript is primarily used for front-end web development, but also for server-
side development (Node.js) and mobile app development (React Native).

Concurrency: Java has built-in support for threads and concurrency through the
java.util.concurrent package, while JavaScript relies on asynchronous programming with
callbacks, promises, and async/await for handling concurrency.

Ecosystem: Java has a mature ecosystem with extensive libraries and frameworks like Spring,
Hibernate, and Android SDK, while JavaScript has a vast ecosystem with libraries and
frameworks like React, Angular, and Express.js.

Compilation: Java code is compiled into bytecode that runs on the Java Virtual Machine (JVM),
while JavaScript code is interpreted or just-in-time compiled by the JavaScript engine in the
browser or Node.js runtime.

You might also like