diff --git a/StudentInfo.txt b/StudentInfo.txt new file mode 100644 index 0000000..9544f4b --- /dev/null +++ b/StudentInfo.txt @@ -0,0 +1,4 @@ +Faris Almutairi +44 47 48 49 +Absence excuse: went to the hospital +4.0 \ No newline at end of file diff --git a/StudentOutput.txt b/StudentOutput.txt new file mode 100644 index 0000000..5b3e51b --- /dev/null +++ b/StudentOutput.txt @@ -0,0 +1,7 @@ +Student information: +Student name: Faris Almutairi +Math: 45 days +Physics: 48 days +Chemistry: 49 days +Programming: 50 days +Grade: 4.0 diff --git a/Task4.class b/Task4.class new file mode 100644 index 0000000..0849887 Binary files /dev/null and b/Task4.class differ diff --git a/Task4.java b/Task4.java new file mode 100644 index 0000000..e609319 --- /dev/null +++ b/Task4.java @@ -0,0 +1,49 @@ +import java.util.Scanner; + +public class Task4 { + public static void main(String[] args){ + Scanner input = new Scanner(System.in); + + System.out.print("Enter student name: "); + String name = input.nextLine(); + + int[] attendance = new int[4]; + + String[] subjects = {"Math", "Physics", "Chemistry", "Programming"}; + for (int i = 0; i < subjects.length; i++) { + System.out.print("Enter attendance for " + subjects[i] + ": "); + attendance[i] = input.nextInt(); + } + + input.nextLine(); + + System.out.print("Mark attendance for each subject (Enter excuse of absence): "); + String excuse = input.nextLine(); + if(excuse.contains("hospital")){ + for (int i = 0; i < attendance.length; i++){ + attendance[i]++; + } + } + + String result; + System.out.print("Enter grade for the semester (out of 5): "); + double grade = Double.parseDouble(input.nextLine()); // Read whole line and parse to int + + if(grade > 3.5){ + result = "Succeed"; + } + else{ + result = "failed"; + } + + System.out.println("Student information:"); + for (int i = 0; i < subjects.length; i++) { + System.out.println(subjects[i] + " Attendance: " + attendance[i] + " days"); + } + System.out.println("Grade: " + grade); + System.out.println("Result: " + result); + + + input.close(); + } +} diff --git a/UseFileIO.class b/UseFileIO.class new file mode 100644 index 0000000..96253ff Binary files /dev/null and b/UseFileIO.class differ diff --git a/UseFileIO.java b/UseFileIO.java new file mode 100644 index 0000000..78ec4e2 --- /dev/null +++ b/UseFileIO.java @@ -0,0 +1,47 @@ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class UseFileIO { + public static void main(String[] args) { + try (BufferedReader inputReader = new BufferedReader(new FileReader("StudentInfo.txt")); + BufferedWriter outputWriter = new BufferedWriter(new FileWriter("StudentOutput.txt"))) { + + String line; + while ((line = inputReader.readLine()) != null) { + String name = line; + String[] attendancesInfo = inputReader.readLine().split(" "); + int[] attendances = new int[attendancesInfo.length]; + + for (int i = 0; i < attendancesInfo.length; i++) { + attendances[i] = Integer.parseInt(attendancesInfo[i]); + } + + String excuse = inputReader.readLine(); + Double grade = Double.parseDouble(inputReader.readLine()); + + if (excuse.contains("hospital")) { + for (int i = 0; i < attendances.length; i++) { + attendances[i]++; + } + } + + String[] subjects = {"Math", "Physics", "Chemistry", "Programming"}; + + // Write in the output file + outputWriter.write("Student information:\n"); + outputWriter.write("Student name: " + name + "\n"); + + for (int i = 0; i < attendances.length; i++) { + outputWriter.write(subjects[i] + ": " + attendances[i] + " days\n"); + } + + outputWriter.write("Grade: " + grade + "\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/test.class b/test.class new file mode 100644 index 0000000..a5952c9 Binary files /dev/null and b/test.class differ