Knowee
Questions
Features
Study Tools

Enter the student details using constructors with arguments and constructors without arguments. Then find the total marks of each student. If it is greater than 500 print pass , else print fail.Input:1Neha123456A100100100100100100outputNeha123456A100100100100100100Pass

Question

Enter the student details using constructors with arguments and constructors without arguments. Then find the total marks of each student. If it is greater than 500 print pass , else print fail.Input:1Neha123456A100100100100100100outputNeha123456A100100100100100100Pass

🧐 Not the exact question you are looking for?Go ask a question

Solution

It seems like you are asking for a simple program in Java that uses constructors to input student details and calculate their total marks. Here is a simple implementation:

class Student {
    String name;
    int rollNo;
    char section;
    int[] marks = new int[6];

    // Constructor without arguments
    Student() {
        this.name = "";
        this.rollNo = 0;
        this.section = 'A';
        for (int i = 0; i < 6; i++) {
            this.marks[i] = 0;
        }
    }

    // Constructor with arguments
    Student(String name, int rollNo, char section, int[] marks) {
        this.name = name;
        this.rollNo = rollNo;
        this.section = section;
        for (int i = 0; i < 6; i++) {
            this.marks[i] = marks[i];
        }
    }

    // Method to calculate total marks
    int calculateTotalMarks() {
        int total = 0;
        for (int mark : this.marks) {
            total += mark;
        }
        return total;
    }

    // Method to check pass or fail
    String checkPassOrFail() {
        int total = calculateTotalMarks();
        if (total > 500) {
            return "Pass";
        } else {
            return "Fail";
        }
    }
}

public class Main {
    public static void main(String[] args) {
        int[] marks = {100, 100, 100, 100, 100, 100};
        Student student = new Student("Neha", 123456, 'A', marks);
        System.out.println(student.name + student.rollNo + student.section);
        for (int mark : student.marks) {
            System.out.print(mark + " ");
        }
        System.out.println();
        System.out.println(student.checkPassOrFail());
    }
}

This program first defines a Student class with two constructors, one without arguments and one with arguments. The calculateTotalMarks method calculates the total marks of a student, and the checkPassOrFail method checks if the total marks are greater than 500. In the main method, a new Student object is created with the given details, and the student's details and pass/fail status are printed.

This problem has been solved

Similar Questions

Constructor and static memberEnter the student details using constructors with arguments and constructors without arguments. Then find the total marks of each student. If it is greater than 500 print pass , else print fail.

Write Python code that ask the user to enter the number of students. After that ask the user to enter a mark for each student using a loop. Save all marks into an empty list using insert() method. Display all marks after finishing data entry.

The first line contains an integer, , the number of students.The subsequent lines describe each student over lines.- The first line contains a student's name.- The second line contains their grade.ConstraintsThere will always be one or more students having the second lowest grade.Output FormatPrint the name(s) of any student(s) having the second lowest grade in. If there are multiple students, order their names alphabetically and print each one on a new line.

Design a Student Mark List Generation System using Java.Define a class to store student's register number, name,attendance percentage and an integer array to store five subject marks.Define methods to read and print the student's details. Generate "InvalidMarksException: Marks must be within the range 0 to 30" , If the marks entered are less than 0 or greater than 30. Generate “InsufficientAttendanceException: Minimum Attendance Required is 75%” , if the attendance is less than 75%. Print the marklist only if there are no exceptions generated.Input FormatRegno – intName – StringAttendance – doubleMark1, Mark2, Mark3, Mark4, Mark5 – int Array elementsOutput FormatIf Exception is generated, display the message thrown by theException.Else, display the student details as shown below.Regno:Name:Attendance:Mark1:Mark2:Mark3:Mark4:Mark5:

In a school, each student is identified by a unique combination of a class section and a roll number. Write a program that takes input for the class section (either uppercase or lowercase character) and the roll number (an integer). The program should then output a message indicating the student's roll number in the specified class section.Input format :The first line of input is a character c, representing the class section (A-Z or a-z).The second line of input is an integer d, representing the roll number.Output format :The output displays a message indicating the roll number and class section in the format: "Roll number d in Section c".Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases will fall under the following constraints:1 ≤ d ≤ 50The class section must be a letter in either uppercase or lowercase.Sample test cases :Input 1 :A30Output 1 :Roll number 30 in Section AInput 2 :D50Output 2 :Roll number 50 in Section DInput 3 :z25Output 3 :Roll number 25 in Section z

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.