Answer to Question #239349 in Java | JSP | JSF for doeboy

Question #239349
Your application must make use of concepts such as arrays, loops, inheritance, constructors
and information hiding. Output must be shown in the form of a report using the console.
In your solution, make use of as many concepts, and components dealt with in this course, but
pay special attention to the following learning units:
• Learning Unit 1: Advanced arrays.
• Learning Unit 2: Introduction to inheritance
1
Expert's answer
2021-09-19T20:42:15-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    
	    int n;
	    Scanner in = new Scanner(System.in);
	    System.out.println("Enter number of student: ");
	    n=in.nextInt();
	    //arrays
		Student [] s=new Student[n];
		
		System.out.println("Enter the details of the "+n+" students:");
		for(int i=0;i<n;i++){
		    s[i].getData();
		}
		
		System.out.println("The details of the "+n+" students are:");
		for(int i=0;i<n;i++){
		    s[i].displayData();
		}
		
		Employee e1=new Employee();
		e1.getData();
		e1.displayData();
	}
}
class Person{
    protected String name;
    protected int age;
    protected String address;
}
//inheritance
class Student extends Person{
    private int reg_no;
    private String course;
    private double fee_balance;
    Scanner in=new Scanner(System.in);
    public Student(int r){
        reg_no=r;
    }
    public Student(){
        
    }
    public void getData(){
        System.out.println("Enter name: ");
        name=in.next();
        System.out.println("Enter age: ");
        age=in.nextInt();
        System.out.println("Enter address: ");
        address=in.next();
        System.out.println("Enter reg number: ");
        reg_no=in.nextInt();
        System.out.println("Enter course: ");
        course=in.next();
        System.out.println("Enter fee balance");
        fee_balance=in.nextDouble();
    }
    public void displayData(){
        System.out.println("Name: "+name);
        System.out.println("Age: "+age);
        System.out.println("Address: "+address);
        System.out.println("Reg number: "+reg_no);
        System.out.println("Course: "+course);
        System.out.println("Fee balance: "+fee_balance);
    }
}
//inheritance
class Employee extends Person{
    private int emp_no;
    private String emp_category;
    private double salary;
    Scanner in=new Scanner(System.in);
    public void getData(){
        System.out.println("Enter name: ");
        name=in.next();
        System.out.println("Enter age: ");
        age=in.nextInt();
        System.out.println("Enter address: ");
        address=in.next();
        System.out.println("Enter Employee number: ");
        emp_no=in.nextInt();
        System.out.println("Enter category: ");
        emp_category=in.next();
        System.out.println("Enter salary");
        salary=in.nextDouble();
    }
    public void displayData(){
        System.out.println("Name: "+name);
        System.out.println("Age: "+age);
        System.out.println("Address: "+address);
        System.out.println("Employee number: "+emp_no);
        System.out.println("Category: "+emp_category);
        System.out.println("Salary: "+salary); 
    }
}

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