Comments (5)
Hello, could you please assign it to me?
from java-hacktoberfest23.
hey @chetannihith , can you assign me?
from java-hacktoberfest23.
`
public class School {
// Data Members
private int rollNo;
private String name;
private String address;
private String branch;
private double[] marks; // Marks in 4 subjects
private double percentage;
private char grade;
// Constructor to initialize the data members
public School(int rollNo, String name, String address, String branch, double[] marks) {
this.rollNo = rollNo;
this.name = name;
this.address = address;
this.branch = branch;
this.marks = marks;
calculatePercentageAndGrade();
}
// Method to calculate the percentage and grade
private void calculatePercentageAndGrade() {
double totalMarks = 0;
for (double mark : marks) {
totalMarks += mark;
}
percentage = totalMarks / 4.0;
if (percentage >= 90) {
grade = 'A';
} else if (percentage >= 80) {
grade = 'B';
} else if (percentage >= 70) {
grade = 'C';
} else if (percentage >= 60) {
grade = 'D';
} else {
grade = 'F';
}
}
// Method to display student information
public void displayStudentInformation() {
System.out.println("Roll No: " + rollNo);
System.out.println("Name: " + name);
System.out.println("Address: " + address);
System.out.println("Branch: " + branch);
System.out.println("Marks in 4 Subjects: ");
for (int i = 0; i < marks.length; i++) {
System.out.println("Subject " + (i + 1) + ": " + marks[i]);
}
System.out.println("Percentage: " + percentage);
System.out.println("Grade: " + grade);
}
public static void main(String[] args) {
// Example usage
double[] studentMarks = {85.5, 92.0, 78.5, 89.0};
School student = new School(101, "John Doe", "123 Main St", "Science", studentMarks);
student.displayStudentInformation();
}
}
`
from java-hacktoberfest23.
import java.util.Scanner;
class School {
private int rollNo;
private String name;
private String address;
private String branch;
private double[] marks;
private double percentage;
private char grade;
// Constructor to initialize student information
public School(int rollNo, String name, String address, String branch, double[] marks) {
this.rollNo = rollNo;
this.name = name;
this.address = address;
this.branch = branch;
this.marks = marks;
this.calculatePercentage();
this.calculateGrade();
}
// Calculate percentage based on marks
private void calculatePercentage() {
double totalMarks = 0;
for (double mark : marks) {
totalMarks += mark;
}
this.percentage = (totalMarks / (marks.length * 100)) * 100;
}
// Calculate grade based on percentage
private void calculateGrade() {
if (percentage >= 90) {
this.grade = 'A';
} else if (percentage >= 80) {
this.grade = 'B';
} else if (percentage >= 70) {
this.grade = 'C';
} else if (percentage >= 60) {
this.grade = 'D';
} else {
this.grade = 'F';
}
}
// Display student information
public void displayStudentInfo() {
System.out.println("Student Information:");
System.out.println("Roll No: " + rollNo);
System.out.println("Name: " + name);
System.out.println("Address: " + address);
System.out.println("Branch: " + branch);
System.out.println("Marks (Subject-wise):");
for (int i = 0; i < marks.length; i++) {
System.out.println("Subject " + (i + 1) + ": " + marks[i]);
}
System.out.println("Percentage: " + percentage + "%");
System.out.println("Grade: " + grade);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input student information
System.out.print("Enter Roll No: ");
int rollNo = scanner.nextInt();
scanner.nextLine(); // Consume the newline
System.out.print("Enter Name: ");
String name = scanner.nextLine();
System.out.print("Enter Address: ");
String address = scanner.nextLine();
System.out.print("Enter Branch: ");
String branch = scanner.nextLine();
System.out.print("Enter Marks in 4 Subjects (space-separated): ");
double[] marks = new double[4];
for (int i = 0; i < 4; i++) {
marks[i] = scanner.nextDouble();
}
// Create a School object with the entered information
School student = new School(rollNo, name, address, branch, marks);
// Display student information
student.displayStudentInfo();
}
}
from java-hacktoberfest23.
@chetannihith can u plz assign this to me
from java-hacktoberfest23.
Related Issues (20)
- Write a Java program to create a package named mypack and import it in circle class. HOT 2
- Write a Java program to create a package named pl, and implement this package in ex1 class. HOT 1
- Write a Java program to create a package which has classes and methods to read Student Admission details. HOT 3
- Solve Question 1 HOT 1
- Solve Question 2 HOT 1
- Solve Question 3.1 HOT 2
- Solve question 3.2 HOT 5
- Solve question 3.3 HOT 1
- Solve question 3.4 HOT 9
- Solve Question 3.5 HOT 10
- Overloading 1.0 HOT 1
- Create a class to print the area of a square and a rectangle. Use methods to assign the values and print the details. HOT 2
- Constructor Overloading HOT 2
- Repository Structuring in proper format HOT 3
- Add CONTRIBUTING.md file HOT 3
- Understanding Types of Inheritance in Java HOT 1
- I want to add the implementation of trie (prefix tree) data structure
- Repository has been Excluded from Hacktoberfest 2023
- Terminal/console based project on Task Manager and Remainder System. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-hacktoberfest23.