Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HOMEWORK #4 QUESTION #2 (JAVA PROGRAM) Design a class SharePattern that has the following two fields: number_of_days_in_period and sharepoints_on_first_day. Class should have a constructor to

HOMEWORK #4 QUESTION #2 (JAVA PROGRAM)

Design a class SharePattern that has the following two fields: number_of_days_in_period and sharepoints_on_first_day. Class should have

a constructor to set the values of these two fields.

a method findFinalDaySharePoints that would return the share points on the final day of the period specified by the number_of_days_in_period field. The share points fluctuate in a similar way as described in Problem 1 of this homework (INCREASE SHARE POINTS BY 50 THAN DECREASE SHARE POINTS BY 25 ON ALTERNATE DAYS).

To test this class, write a HW4_Q2_YourStudentId_Demo class. In the main method of this class, the user will be asked to enter the number of days in the specified period and the share points on the first day. Then the object of SharePattern class is created using the constructor and the share point on the final day is obtained by calling the findFinalDaySharePoints method and displayed as shown below:

For example, if a user enters as follows:

Number of the days in the period: 11

Share points on the first day: 550

Then the program should display the following:

The share points on the final day would be: 675

HOMEWORK #4 QUESTION #1 (FOR REFERENCE)

HOMEWORK #4 QUESTION #1

Write a Java program that contains a method named DisplayStock. The input arguments to this method are the number of days in the period and the share points on the first day. The method is used to increase the share points by 50 and decrease the share points by 25 on alternate days in the specified period. The method then displays a table showing the days and the share points on those days (as shown below). The method doesnt return anything.

The main method in the program will first ask the users to enter the number of days in the specified period and the share points on the first day (with input validation, in the same way as Problem 1 in Homework #3). The program should then call the DisplayStock method that outputs the table (as shown below).

For example, if a user enters as below:

Number of days in the period: 11 Share points on the first day: 550 The program (using the DisplayStock method) outputs the following: Day Share Points

1 550

2 600

3 575 4 625

5 600

6 650

7 625

8 675

9 650

10 700

11 675

HOMEWORK #3 QUESTION #1 (FOR REFERENCE TO HW#4 Q#1)

Assume that the share points of a company fluctuate with a particular pattern in the New York Stock Exchange. It increases by 50 points every day in the first half of a given period and decreases by 25 points in the second half. If the number of days in a given period is odd, the first half is considered a day more than the second half.

Write a Java program that will first ask users to enter the number of days in a given period and the share points on the first day. The number of days that is entered must not be less than 10 and more than 20. If it is not so, the user must be prompted to enter the input again with the following message: The number of days doesnt meet the required criteria, enter it again. The program should output a table showing the days and the share points on those days.

For example, if a user enters as below:

Number of days in the period: 11 Share points on the first day: 550 The program should output the following: Day Share Points

1 550

2 600

3 650

4 700

5 750

6 800

7 775

8 750

9 725

10 700

11 675

CODE FOR HOMEWORK #3 QUESTION #1 (FOR REFERENCE)

//Import scanner for future use import java.util.Scanner; public class HW3_Q1 { public static void main(String[] args) { //Declare variables int points, day, totalDays; //Create Scanner class object to get inputs from the user Scanner sc = new Scanner(System.in); //While loop executes until the user enters a valid number while (true) { //Get input entered by the user and make sure if fits the criteria System.out.print("Number of days in the period: "); totalDays = sc.nextInt(); if (totalDays < 10 || totalDays> 20) { //Lets the user know that the number they entered in not valid System.out.println("The number of days doesn't meet the required criteria, enter it again"); } else break; } //Getting the input from user for share points System.out.print("Share points on the first day: "); points = sc.nextInt(); //Display the output System.out.println("Day Share Points"); //Determines if the days are odd or even then executes code according to the user input if (totalDays % 2 != 0) { int i = 0; System.out.println(i + 1 + "\t" + points); for (i = 1; i < (totalDays / 2) + 1; i++) { points += 50; System.out.println(i + 1 + "\t" + points); } for (i = (totalDays / 2) + 1; i < totalDays; i++) { points -=25; System.out.println(i + 1 + "\t" + points); } } else { int i = 0; System.out.println(i + 1 + "\t" + points); for (i = 1; i < (totalDays / 2); i++) { points +=50; System.out.println(i + 1 + "\t" + points); } for (i = (totalDays / 2) + 1; i < totalDays; i++) { points -= 25; System.out.println(i + 1 + "\t" + points); } } //Display the output } }

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

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions