Answer to Question #246575 in Java | JSP | JSF for Aubrey Eso Jozela

Question #246575
Code a method named createStudent(). This method has no parameters, but returns a Student object. a) Define a Scanner variable to read from the keyboard. b) Define variables for name, student number and loan amount. Prompt the user to type data values for each of the variables and then read the values from the keyboard. c) Define and create a Student object from the data read from the keyboard. d) Return this Student object. 4 Code a method named createPostGraduate(). This method has no parameters, but returns a PostGraduate object. a. Define a Scanner variable to read from the keyboard. b. Define variables for name, student number and loan amount and thesis. Prompt the user to type data values for each of the variables and then read the values from the keyboard. c. Define and create a PostGraduate object from the data read from the keyboard. d. Return this PostGraduate object.
1
Expert's answer
2021-10-12T05:14:32-0400


package teststudent;


import java.util.Scanner;


class Student{
   private String name;
   private int number;
   private float loan_amount;
   Student(String n, int nu, float l){
       name = n;
       number = nu;
       loan_amount = l;
       
   }
   Student createStudent(){
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter the student name\n");
       String n = scan.nextLine();
       System.out.println("Enter the student number\n");
       int nu = scan.nextInt();
       System.out.println("Enter the loan amount\n");
       float amount = scan.nextFloat();
       Student st = new Student(n,nu, amount);
       return st;
       
   }
}


class  PostGraduate{
     private String name, thesis;
   private int number;
   private float loan_amount;
    PostGraduate(String n, int nu, float l, String t){
        name = n;
       number = nu;
       loan_amount = l;
       thesis = t;
    }
   PostGraduate createPostGraduate(){
        Scanner scan = new Scanner(System.in);
       System.out.println("Enter the student name\n");
       String n = scan.nextLine();
       System.out.println("Enter the student number\n");
       int nu = scan.nextInt();
       System.out.println("Enter the loan amount\n");
       float amount = scan.nextFloat();
       System.out.println("Enter the thesis\n");
       String t = scan.nextLine();
       PostGraduate st = new PostGraduate(n,nu, amount,t);
       return st;
   }
}
public class TestStudent {


    
    public static void main(String[] args) {
        
    }
    
}

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