SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //java
  2.  
  3.  
  4. //student class
  5. package User;
  6.  
  7. import java.util.Scanner;
  8.  
  9.  
  10. public class Student extends Person {
  11.     public Student ()
  12.     {
  13.     super();
  14.     sId = 0;
  15.     major = "TBA";
  16.     cgpa = 0.0f;
  17.     }
  18.  
  19.     public Student(int sId, float cgpa, String major) {
  20.         this.sId = sId;
  21.         this.cgpa = cgpa;
  22.         this.major = major;
  23.     }
  24.     int sId; float cgpa; String major;
  25.     void setStudentInfo()
  26.     {
  27.         Scanner s = new Scanner(System.in);
  28.         System.out.println("Enter id: ");
  29.         sId = s.nextInt();
  30.         setPersonInfo();
  31.         System.out.println("Enter cgpa: ");
  32.         cgpa = s.nextFloat();
  33.         System.out.println("enter major: ");
  34.         major = s.nextLine();
  35.     }
  36.     void showStudentInfo()
  37.     {
  38.         System.out.println(sId+"ID =");
  39.         showPersonInfo();
  40.         System.out.println("major = "+major);
  41.     }
  42. }
  43.  
  44. //person class
  45.  
  46. package User;
  47.  
  48. import java.util.Scanner;
  49.  
  50.  
  51. public class Person {
  52.  
  53.     public Person(String name, String dob, String bg) {
  54.         this.name = name;
  55.         this.dob = dob;
  56.         this.bg = bg;
  57.     }
  58.  
  59.     public String getName() {
  60.         return name;
  61.     }
  62.  
  63.     public String getDob() {
  64.         return dob;
  65.     }
  66.  
  67.     public String getBg() {
  68.         return bg;
  69.     }
  70.  
  71.     public void setName(String name) {
  72.         this.name = name;
  73.     }
  74.  
  75.     public void setDob(String dob) {
  76.         this.dob = dob;
  77.     }
  78.  
  79.     public void setBg(String bg) {
  80.         this.bg = bg;
  81.     }
  82.     //private String name, dob, bg;
  83.     protected String name, dob, bg;
  84.     public Person()
  85.     {
  86.         name=dob=bg="TBA";
  87.     }
  88.  
  89.     public void setPersonInfo()
  90.     {
  91.     Scanner s= new Scanner(System.in);
  92.         System.out.println("Enter Name : ");
  93.        name =  s.nextLine();
  94.         System.out.println("Enter dob : ");
  95.         dob = s.nextLine();
  96.         bg = s.nextLine();
  97.     }
  98.    
  99.     public void showPersonInfo()
  100.     {
  101.         System.out.println("name =" +name+"bob= "+dob+"bg +"+bg);
  102.    
  103.     }
  104. }
  105. /////main class
  106.  
  107.  
  108. package mainpkg;
  109. import User.Person;
  110. import User.Student;
  111. public class Mainclass {
  112.  
  113.    
  114.     public static void main(String[] args) {
  115.        Student s = new Student();
  116.        Person p = new Person();
  117.         System.out.println(" ");
  118.     }
  119.    
  120. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top