0% found this document useful (0 votes)
17 views

Anwer-question-1-3

The document contains two Java programs. The first program reverses an array of floating-point numbers and outputs the reversed array. The second program calculates a student's CGPA based on their course credits and marks, and outputs the student's ID, total credits, CGPA, and corresponding grade.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Anwer-question-1-3

The document contains two Java programs. The first program reverses an array of floating-point numbers and outputs the reversed array. The second program calculates a student's CGPA based on their course credits and marks, and outputs the student's ID, total credits, CGPA, and corresponding grade.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Code for Question answer 1:

-----------------------------------------------------------

public class ReverseArray {


public static void reverse(float[] arr) {
int l = 0, r = arr.length - 1;
while (l < r) {
float temp = arr[l];
arr[l] = arr[r];
arr[r] = temp;
l++;
r--;
}
}

public static void main(String[] args) {


float[] arr = {5.8f, 2.6f, 9.0f, 3.4f, 7.1f};
reverse(arr);
for (float num : arr) {
System.out.print(num + " ");
}
}
}
----------------------------------------------------------

Output for Question 1:

7.1 3.4 9.0 2.6 5.8


---------------------------------------------------------

Code for Question Answer 3:

import java.util.Scanner;

class StudentCGPA {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter Student ID: ");


String studentID = scanner.nextLine();

System.out.print("Enter number of courses: ");


int numCourses = scanner.nextInt();

int totalCredits = 0, totalWeightedGrade = 0;

for (int i = 1; i <= numCourses; i++) {


System.out.println("Course " + i + ":");
System.out.print("Credit (Max 3): ");
int credit = scanner.nextInt();

System.out.print("CT (Max 30): ");


int ct = scanner.nextInt();

System.out.print("AT (Max 10): ");


int at = scanner.nextInt();

System.out.print("FE (Max 60): ");


int fe = scanner.nextInt();

int totalMarks = ct + at + fe;


double gradePoint = getGradePoint(totalMarks);

totalCredits += credit;
totalWeightedGrade += credit * gradePoint;
}

double cgpa = totalWeightedGrade / (double) totalCredits;


String grade = getGrade(cgpa);

System.out.println("\nStudent ID: " + studentID);


System.out.println("Credit Taken: " + totalCredits);
System.out.println("Credit Earned: " + totalCredits);
System.out.println("CGPA: " + String.format("%.2f", cgpa));
System.out.println("Grade: " + grade);
}

private static double getGradePoint(int marks) {


if (marks >= 80) return 4.0;
else if (marks >= 75) return 3.75;
else if (marks >= 70) return 3.5;
else if (marks >= 65) return 3.25;
else if (marks >= 60) return 3.0;
else if (marks >= 55) return 2.75;
else if (marks >= 50) return 2.5;
else if (marks >= 45) return 2.25;
else if (marks >= 40) return 2.0;
else return 0.0;
}

private static String getGrade(double cgpa) {


if (cgpa >= 3.75) return "A";
else if (cgpa >= 3.5) return "A-";
else if (cgpa >= 3.25) return "B+";
else if (cgpa >= 3.0) return "B";
else if (cgpa >= 2.75) return "B-";
else if (cgpa >= 2.5) return "C+";
else if (cgpa >= 2.25) return "C";
else if (cgpa >= 2.0) return "D";
else return "F";
}
}
----------------------------------------

Output for question 2:


---------------------------------------

Enter Student ID: IT23013


Enter number of courses: 3
Course 1:
Credit (Max 3): 3
CT (Max 30): 20
AT (Max 10): 8
FE (Max 60): 30
Course 2:
Credit (Max 3): 3
CT (Max 30): 20
AT (Max 10): 8
FE (Max 60): 30
Course 3:
Credit (Max 3): 3
CT (Max 30): 21
AT (Max 10): 10
FE (Max 60): 35

Student ID: IT23013


Credit Taken: 9
Credit Earned: 9
CGPA: 2,78
Grade: B-

You might also like