Answer to Question #337895 in Java | JSP | JSF for Nono

Question #337895

Use the concepts of object-oriented programming to develop a program that constitutes the following two classes:



Student-stores student number and surname




Result-contains the marks obtained in two subjects, inherits student details from Student and also uses the method from Student.The program should calculate the average degree mark from the two subjects and display the student details and the total of the marks obtained in each subject.

1
Expert's answer
2022-05-06T15:36:13-0400
import java.util.Scanner;

public class Answer {
    public static class Student {
        int number;
        String Surname;

        public Student(int number, String surname) {
            this.number = number;
            Surname = surname;
        }
        public void info() {
            System.out.println("Num: " + number + " Sur: " + Surname);
        }
        public void setNumber(int number) {
            this.number = number;
        }

        public void setSurname(String surname) {
            Surname = surname;
        }
    }
    public static class Result extends Student{
        int subjects1;
        int subjects2;

        public Result(int number, String surname, int subjects1, int subjects2) {
            super(number, surname);
            this.subjects1 = subjects1;
            this.subjects2 = subjects2;
        }

        int avr(){
            return (subjects1 + subjects2) / 2;
        }
        void infoSub() {
            System.out.println("Sub1: " + subjects1 + " Sub1: " + subjects2);
        }

        public void setSubjects1(int subjects1) {
            this.subjects1 = subjects1;
        }

        public void setSubjects2(int subjects2) {
            this.subjects2 = subjects2;
        }
    }
    public static void main(String[] args) {
        Student student = new Student(1, "Smith");
        Result result = new Result(student.number, student.Surname, 45, 56);
        result.info();
        result.infoSub();
        System.out.println("Avr: " + result.avr());
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS