Answer to Question #246032 in Java | JSP | JSF for Chadwin Fritz

Question #246032

StudentLoans class 

3 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-05T10:16:13-0400
import java.util.Scanner;

public class StudentLoans {
    public Student createStudent() {
        Scanner in = new Scanner(System.in);
        System.out.println("Name:");
        String name = in.nextLine();
        System.out.println("Student number:");
        String studentNumber = in.nextLine();
        System.out.println("Loan amount:");
        double loanAmount = Double.parseDouble(in.nextLine());
        return new Student(name, studentNumber, loanAmount);
    }

    public PostGraduate createPostGraduate() {
        Scanner in = new Scanner(System.in);
        System.out.println("Name:");
        String name = in.nextLine();
        System.out.println("Student number:");
        String studentNumber = in.nextLine();
        System.out.println("Loan amount:");
        double loanAmount = Double.parseDouble(in.nextLine());
        System.out.println("Thesis:");
        String thesis = in.nextLine();
        return new PostGraduate(name, studentNumber, loanAmount, thesis);
    }
}

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