Question
Write a java program xxxxxH1.java (where xxxxx is at most the 1 st five characters of your last name) that gets 4 integers n, a,
Write a java program xxxxxH1.java (where xxxxx is at most the 1st five characters of your last name) that gets 4 integers n, a, b and k from program argument and calls generate (n, a, b, k). NOTE: Your generate method must be private.
For further details please see oddsPa.java program.
Make sure to use formatted output.
5- Upload xxxxxH1.java (only one java file) in canvas before midnight Feb. 4, 23
To compile: javac xxxxxH1.java
Example to execute xxxxxH1.java to generate 80 random integers from 200 ... 300 and print them 15 integers per line: java xxxxxH1 80 200 300 15
Your main method should be as follow:
1 // main program gets input from program argument
2 public static void main(String args[]) throws Exception{
3 // declare variables
4 int n, a, b, k, cnt;
5
6 //create an instance of a class
7 xxxxxH1 g = new xxxxxH1 ();
8
9
10 // get no. of arguments
11 cnt = args.length;
12
13 if (cnt < 4) {
14 System.out.printf(" \tOOPS Invalid No. of aguments! EXIT. ");
15 return;
16 }
17
18 // get values of n, a, b and k from program argument
19 n = Integer.parseInt(args[0]);
20 a = Integer.parseInt(args[1]);
21 b = Integer.parseInt(args[2]);
22 k = Integer.parseInt(args[3]);
23
24 //Its a good practice to print input in program output!
25 // formatted print
26 System.out.printf(" \tINPUT: n = %4d, a = %4d, b = %4d, k = %4d", n, a, b, k);
27
28 // Call generate Method
29 g.generate(n, a, b, k);
30
31 //Pleas replace G. Dastghaibyfard with your name in next line
32 System.out.printf(" \tAuthor: G. Dastghaibyfard Date: %s ",
33 java.time.LocalDate.now());
34 } // end main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started