Java SYMarks Packages, Compiling and Code
Java SYMarks Packages, Compiling and Code
2 Write a Java program to create a Package “SY” which has a class SYMarks (members –
ComputerTotal, MathsTotal, and ElectronicsTotal). Create another package TY which has a
class
TYMarks (members – Theory, Practicals). Create n objects of Student class (having
rollNumber,
name, SYMarks and TYMarks). Add the marks of SY and TY computer subjects and
calculate
the Grade (‘A’ for >= 70, ‘B’ for >= 60 ‘C’ for >= 50 , Pass Class for > =40 else ‘FAIL’) and
display the result of the student in proper format.
What do you want to do with the text?
You
Sent by you:
java program and then sample example
Copilot
Generating answer using selected text
Sent by Copilot:
Sure! Here’s a Java program that fulfills the requirements of the given problem statement.
The program creates two packages, SY and TY, with the respective
classes SYMarks and TYMarks. It then creates a Student class to manage student details and
calculate grades.
Step-by-Step Solution
Java
// File: SY/SYMarks.java
package SY;
@Override
public String toString() {
return ComputerTotal + "\t" + MathsTotal + "\t" + ElectronicsTotal;
}
}
AI-generated code. Review and use carefully. More info on FAQ.
2. Create the TY package with the TYMarks class:
Java
// File: TY/TYMarks.java
package TY;
@Override
public String toString() {
return Theory + "\t" + Practicals;
}
}
AI-generated code. Review and use carefully. More info on FAQ.
3. Create the Student class to manage student details and calculate grades:
Java
// File: Student.java
import SY.SYMarks;
import TY.TYMarks;
import java.util.Scanner;
@Override
public String toString() {
return rollNumber + "\t" + name + "\t" + syMarks + "\t" + tyMarks;
}
scanner.close();
}
}
AI-generated code. Review and use carefully. More info on FAQ.
Explanation
Packages and Classes: The program defines two packages, SY and TY, each containing a
class (SYMarks and TYMarks respectively) to hold the marks.
Student Class: The Student class contains fields for roll number, name, and marks from
both SY and TY. It includes methods to calculate the grade based on the marks and to display
student details.
Main Method: The main method accepts input for multiple students,
creates Student objects, and displays their details along with calculated grades.
Feel free to ask if you have any questions or need further assistance!
Learn more
1github.com2github.com3onecompiler.com4github.com
You
Sent by you:
please give me sample output for given java code
Copilot
Usingthe web
Sent by Copilot:
Sure! Here’s a sample output for the given Java code. Let’s assume we have 2 students with
the following details:
1. Student 1:
o Roll Number: 1
o Name: Alice
o SY Marks: Computer: 75, Maths: 80, Electronics: 70
o TY Marks: Theory: 65, Practicals: 70
2. Student 2:
o Roll Number: 2
o Name: Bob
o SY Marks: Computer: 55, Maths: 60, Electronics: 50
o TY Marks: Theory: 45, Practicals: 50
Sample Output
Enter number of students: 2
Enter details for student 1:
Roll Number: 1
Name: Alice
SY Marks (Computer, Maths, Electronics): 75 80 70
TY Marks (Theory, Practicals): 65 70
Student Details:
RollNo Name SYMarks TYMarks Grade
1 Alice 75 80 70 65 70 A
2 Bob 55 60 50 45 50 C
Explanation
Student 1: The total marks for computer-related subjects are (75 (SY) + 65 (Theory) + 70
(Practicals) = 210). The average is (210 / 3 = 70), which corresponds to grade ‘A’.
Student 2: The total marks for computer-related subjects are (55 (SY) + 45 (Theory) + 50
(Practicals) = 150). The average is (150 / 3 = 50), which corresponds to grade ‘C’.
Feel free to modify the input values and run the program to see different outputs! If you have
any more questions or need further assistance, just let me know.
To compile and run the Java program with packages, follow these steps:
Example
Here’s how it looks in the terminal:
$ cd project
$ javac SY/SYMarks.java
$ javac TY/TYMarks.java
$ javac -cp . Student.java
$ java -cp . Student
Output
After running the program, you will be prompted to enter the number of students
and their details. The program will then display the student details along with their
grades.
If you follow these steps, you should be able to compile and run the program
successfully. Let me know if you encounter any issues or have further questions!