Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions StudentInfo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Faris Almutairi
44 47 48 49
Absence excuse: went to the hospital
4.0
7 changes: 7 additions & 0 deletions StudentOutput.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file added Task4.class
Binary file not shown.
49 changes: 49 additions & 0 deletions Task4.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Binary file added UseFileIO.class
Binary file not shown.
47 changes: 47 additions & 0 deletions UseFileIO.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Binary file added test.class
Binary file not shown.