Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PRE-INFORMATION REQUESTED BY YOU (**I ALREADY COMPLETED THIS 3 PARTS) ______________________________________________ ACTUAL QUESTIONS ASKED (HELP)____________________________________________________ This is using java (INTELLI J) and Gradle. I am

PRE-INFORMATION REQUESTED BY YOU (**I ALREADY COMPLETED THIS 3 PARTS) ______________________________________________

image text in transcribed

ACTUAL QUESTIONS ASKED (HELP)____________________________________________________

image text in transcribed

This is using java (INTELLI J) and Gradle. I am preparing for my first test. I will appreciate if you can help me to solve those problems. I am starting learning programming+ java, so it is kinda difficult for me to solve and get the correct results of this.

****PLEASE, If you make a comment before making each part, I will appreciate it. (EX. //methods for ... ). It will help me to understand and follow what you are writing and doing.

THANK YOU!

Question 1 Create a class called InvalidParamterException that extends the java class named Exception. Add a single constructor that accepts a String argument. The constructor simply calls the parent class (hint: remember what the keyword super does) using the String passed to constructor. Question 2 Create an interface called Investment with the following methods: name: returnValue, arguments: none, returns: double, access: public, throws: InvalidParameterExcep- tion name: returnProfit, arguments: none, returns: double , access: public, throws: InvalidParameterExcep- tion Question 3 a) Create a class called Cash Money that implements Investment with the following fields: name: amount, type: double, access: private name: monthlyInterest, type: double, access: private name: investment Months, type: int, access: private b) Create a default and a parameterized constructor for the CashMney class. The parameterized constructor should accept all 3 fields in the class. c) Populate the approriate methods from the Investment interface. Use the interest rate and number of months of investment investment Months) to calculate the value and profit of the investment. Don't overthink this. Use the following formula to calulate the value of the investment: value = amount x (1 + rate number of periods profit = value - amount d) In your return Value method, determine if either the interest rate or length of investment is negative. If so, throw a custom InvalidParameterException with the message below. Note that a try/catch is not required in this method. CashMoney field values are not all valid Question In this question your are asked to consider an investment called Shares. In this context, shares can either represent the shares of a mutual funds that an inidividual owns or the shares of a particular stock that an individual owns. Questions 5 and 6 will ask you to formally expand the notion of stocks and mutual funds. a) Create an abstract class named Shares that implements Investment with the following fields: name: id, type: String, access: public name: sharePrice, type: double, access: public name: sharedPrice, type: double, access: public b) Add a default constructor and a parameterized consructor that initializes all 3 fields in the class. c) Add the necessary abstract methods needed to implement Investment Question Create a class named Stock that extends Shares with the following fields: a) - name: numberShares, type: int, access: public a Add a default constructor and a parameterized consructor that initializes all fields from the Shares class and the additional field in the Stock class. a) Implement the methods required because we are extending Shares. (Note: the math to implement these methods is very simple) Question Create a class named MFund that extends Shares with the following fields: a) - name: numberShares, type: double, access: public a) Add a default constructor and a parameterized consructor that initializes all fields from the Shares class and the additional field in the Stock class. a) Implement the methods required because we are extending Shares. (Note, again: the math to implement these methods is very simple) Question Create a class called Investment Tester that does the following: a) Creates CashMoney, MFund and Stock objects with values initialized to your choosing. b) Adds the three objects to an ArrayList named Portfolio (you should determine the correct type of the ArrayList) c) Gets the profit associated with the CashMoney investement and prints it to screen with an appropriate label. Uses a try/catch to catch an InvalidParameterException if the interest rate or length of investment associated with your Cash Money are not valid. Question 1 Create a class called InvalidParamterException that extends the java class named Exception. Add a single constructor that accepts a String argument. The constructor simply calls the parent class (hint: remember what the keyword super does) using the String passed to constructor. Question 2 Create an interface called Investment with the following methods: name: returnValue, arguments: none, returns: double, access: public, throws: InvalidParameterExcep- tion name: returnProfit, arguments: none, returns: double , access: public, throws: InvalidParameterExcep- tion Question 3 a) Create a class called Cash Money that implements Investment with the following fields: name: amount, type: double, access: private name: monthlyInterest, type: double, access: private name: investment Months, type: int, access: private b) Create a default and a parameterized constructor for the CashMney class. The parameterized constructor should accept all 3 fields in the class. c) Populate the approriate methods from the Investment interface. Use the interest rate and number of months of investment investment Months) to calculate the value and profit of the investment. Don't overthink this. Use the following formula to calulate the value of the investment: value = amount x (1 + rate number of periods profit = value - amount d) In your return Value method, determine if either the interest rate or length of investment is negative. If so, throw a custom InvalidParameterException with the message below. Note that a try/catch is not required in this method. CashMoney field values are not all valid Question In this question your are asked to consider an investment called Shares. In this context, shares can either represent the shares of a mutual funds that an inidividual owns or the shares of a particular stock that an individual owns. Questions 5 and 6 will ask you to formally expand the notion of stocks and mutual funds. a) Create an abstract class named Shares that implements Investment with the following fields: name: id, type: String, access: public name: sharePrice, type: double, access: public name: sharedPrice, type: double, access: public b) Add a default constructor and a parameterized consructor that initializes all 3 fields in the class. c) Add the necessary abstract methods needed to implement Investment Question Create a class named Stock that extends Shares with the following fields: a) - name: numberShares, type: int, access: public a Add a default constructor and a parameterized consructor that initializes all fields from the Shares class and the additional field in the Stock class. a) Implement the methods required because we are extending Shares. (Note: the math to implement these methods is very simple) Question Create a class named MFund that extends Shares with the following fields: a) - name: numberShares, type: double, access: public a) Add a default constructor and a parameterized consructor that initializes all fields from the Shares class and the additional field in the Stock class. a) Implement the methods required because we are extending Shares. (Note, again: the math to implement these methods is very simple) Question Create a class called Investment Tester that does the following: a) Creates CashMoney, MFund and Stock objects with values initialized to your choosing. b) Adds the three objects to an ArrayList named Portfolio (you should determine the correct type of the ArrayList) c) Gets the profit associated with the CashMoney investement and prints it to screen with an appropriate label. Uses a try/catch to catch an InvalidParameterException if the interest rate or length of investment associated with your Cash Money are not valid

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Students also viewed these Databases questions

Question

What is 2100 (mod 5)?

Answered: 1 week ago

Question

Evaluate employees readiness for training. page 275

Answered: 1 week ago