Answer to Question #238637 in Java | JSP | JSF for AMG

Question #238637

You have to design your own Java console application about any valid problem that your application must solve. Your solution can include solving a business problem, a new idea or even a game. 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. 


1
Expert's answer
2021-09-17T17:32:30-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		Student s1=new Student();
		s1.getData();
		s1.displayData();
		
		Employee e1=new Employee();
		e1.getData();
		e1.displayData();
	}
}
class Person{
    protected String name;
    protected int age;
    protected String address;
}
class Student extends Person{
    private int reg_no;
    private String course;
    private double fee_balance;
    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 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);
    }
}
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