Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want a program to take input from user and build a new class that inherits existing parent class and its functions. is it possible

I want a program to take input from user and build a new class that inherits existing parent class and its functions. is it possible to do so, if yes how do i do that? (Please include a short code).

i am expecting the program to build a new .java class file with the name entered by the user

 

I have got a parent class Client which needs to be inherited by class name entered by user.

public abstract class Client {

    protected final int id;
    protected final String name;
    protected double discountedAmount;

    public Client(int id, String name) {
        this.id = id;
        this.name = name;
    }
}

Also I have got a AddClient class which implements Driver class that runs the program

import java.util.Scanner;
public class AddClient implements Driver {

    @Override
    public void welcome() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Do you want to add new Client Tier?");
        String answer = scanner.next();
        if (answer.equals("Yes")) {
                System.out.println("Enter new client type:");
                String newClient = scanner.next();
                System.out.println("Enter Discount percent:");
                double discount = scanner.nextDouble();
                System.out.println("The new Client is" + " " + newClient + " " + "with a discount of" + " " + discount + "%");

            }
            else if (answer.equals("yes")) {
                System.out.println("Enter new client type:");
                String newClient = scanner.next();
                System.out.println("Enter Discount percent:");
                double discount = scanner.nextDouble();
                System.out.println("The new Client is" + " " + newClient + " " + "with a discount of" + " " + discount + "%");
            }

                Menu menu = new Menu();
                menu.displayUserMenu();
            }
        }

Please suggest me how I am able to create new class that extends the parent class Client from the above user input. 


Step by Step Solution

There are 3 Steps involved in it

Step: 1

You can achieve this by dynamically creating a new Java class file that extends the Client class bas... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting Information Systems

Authors: George H. Bodnar, William S. Hopwood

11th Edition

0132871939, 978-0132871938

More Books

Students also viewed these Programming questions

Question

Implement the method contains() for HashST.

Answered: 1 week ago

Question

Describe six general characteristics of William Jamess philosophy.

Answered: 1 week ago

Question

A 300N F 30% d 2 m Answered: 1 week ago

Answered: 1 week ago