Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

5/21/2021 Assignment https://scis.lms.athabascau.ca/mod/assign/view.php?id=39106 1/3 Java Programs The following exercises do not require any input from the user but will produce output. Everything...

1 answer below »
5/21/2021 Assignment
https:
scis.lms.athabascau.ca/mod/assign/view.php?id=39106 1/3
Java Programs
The following exercises do not require any input from the user but will produce output. Everything
equired to execute the program should be provided in the main() method.
Complete, working, and tested programs are required to solve the following exercises. See Documentation
and Test Plans for required documentation.
In programs 1 to 3, classes have not been specified. You must use Assignment1QuestionN as the class
name and Assignment1QuestionN.java as the file name (where N is 1, 2, or 3).
In programs 4 and 5, class names have been specified. You must use the supplied class name for both class
and source file name (i.e., Animal will be in a file Animal.java).
DO NOT use packages in your programs. All programs for this assignment should reside, compile, and
execute from a single working directory.
1. Write a program that generates 60 pairs of random integers (int) with values between 1 and XXXXXXXXXXFor each
generated pair, use an if-else statement to classify the first value as greater than, less than, or equal to the second
value. For output, display BOTH generated values, as well as the classification, in the format “Number 1
classification > Number 2”, one number pair per output line, where < classification > is one of the phrases “less
than,” “equals,” or “greater than.”
2. Write a program that uses two nested for loops and the modulus operator (%) to detect and print prime numbers.
Prime numbers are integral numbers that are evenly divisible only by themselves and 1. Use your program to print
all the prime numbers from 0 to XXXXXXXXXXPrint 10 numbers per output line, with two spaces after each number.
3. Write a program that creates and initializes a two-dimensional a
ay of primitive type double. The size of the a
ay
is determined by the arguments of the method, and the initialization values are a range determined by the beginning
and ending values that are also arguments of the method (so four arguments total). Create a second method that will
print the a
ay generated by the first method. In main(), test the methods by creating and printing several different
sizes of a
ays.
4. Write a class called Animal with an overloaded sound() method. This method should be overloaded based on
various primitive data types and print different types of animal sounds (“oink,” “honk,” etc.) depending on which
overloaded version is called. Write a main() that calls all the different versions. Note: The sound() method does not
generate the sound; it only prints the sound word as output. In main(), test the methods by calling all the overloaded
methods to print animal sounds.
5. Create a class called Elevator that can be moved between floors in an N-storey building. Elevatoruses a constructo
to initialize the number of floors in the building when the object is instantiated. Elevator also has a default
constructor that creates a two-storey (2) building. Elevator has a termination condition that requires the elevator to
e moved to the main (i.e., first) floor when the object is cleaned up. Write a finalize() method that satisfies this
termination condition and verifies the condition by printing a message to the output. In main(), test the possible
scenarios (i.e., create, move from one floor to another, etc.) that can occur when your Elevator is used in a building
5/21/2021 Assignment
https:
scis.lms.athabascau.ca/mod/assign/view.php?id=39106 2/3
with many floors. (Hint: Termination occurs when the instance is set to null. You may wish to investigate “ga
age
collection” for this exercise.)
Documentation and Test Plans
You may have encountered documentation and test plans in other courses or at your workplace. For this
course, the following are mandatory and should be followed. If the standards for this course differ from
others in your past experience, then, for these assignments, the standards of this course supercede all othe
standards.
At the top of every source file, you must place three comment blocks.
The first comment block contains your name, student ID, date, assignment number, program name, and a
ief program description.
The second comment block is the primary documentation for your program. Explain the program purpose,
code behaviours, and any particulars of the program. Also include detailed instructions for compiling and
executing the program, including example input data if required. Also list separately all classes and
instance variables used in the program, with descriptions.
The third comment block is the test plan. At its core, a test plan simply tells another person how the
program actually worked during testing. In cases where there is no input, there is still often output, so you
can still show exactly how the program should function. In programs with input, you can also describe
various test cases, including those where inco
ect data (or no data) is entered and what output should be
expected. Finally, the test plan is a place to discuss limitations of your program and things that could be
done to improve it.
If you write a program with multiple classes, the first two comment blocks must appear in every source
(class) file. The test plan comment block should only appear in the source file that contains
the main()method used for testing.
Failure to provide all three comment blocks will result in loss of marks, as noted below in Marking
Scheme.
The program “GoodDocs.java” is provided as a complete working example of a program documented to
the standards of this course. (See Resources & Tools in the right-hand column of the course home page.)
Deliverables
Be sure your working directory contains only source code files and any necessary input files as required by
the assignment. Zip this directory into a single zip file and then upload it using the assignment drop box.
https:
comp501r6.athabascau.ca
esources/GoodDocs.java
5/21/2021 Assignment
https:
scis.lms.athabascau.ca/mod/assign/view.php?id=39106 3/3
If you experience difficulty uploading the file, contact your tutor before the due date. Once the due
date has passed, late penalties are in effect whether you have had difficulties or not.
Note: Your tutor will not accept assignments by email.
Marking Scheme
Your assignment is evaluated using the following marking scheme:
Program compiles without e
ors or warnings 20%
Program executes co
ectly 20%
Source code meets the exercise requirements without e
ors 20%
Documentation is provided as required 20%
Test plan is complete 20%
Cautions
If your program does not compile, you will lose both compile marks and execution marks, and most likely,
also some code marks.
If you use components, code fragments, methods, or other work that you did not write yourself, you must
clearly show the authorship of that code, including the author’s name and where the code was obtained.
This should be done in the documentation comment block. No more than 20% of your program can be the
work of others.
If you use the work of others without proper attribution, this is plagiarism and will be penalized with a
mark of 0 on the assignment and possible failure of the course.
Answered Same Day May 21, 2021

Solution

Nithin answered on May 22 2021
146 Votes
JavaAssingment/Assignment1Question3.java
JavaAssingment/Assignment1Question3.java
*
    Name                    :
    Student ID              :
    Date                    :
    Assignment Number       : 1
    Program Name            : Assignment1Question3
    Program Description     : Two dimensional a
ay example
 *
*
    DOCUMENTATION...
 *
*
    Program Purpose         : This program demonstrates working on two dimensional a
ays.
                              Math.random() is used to initialize values in the given range.
    Extra Requirements      : java.lang.Math
    Compile                 : javac Assignment1Question3.java
    Run                     : java Assignment1Question3
    Class name              : Assignment1Question3, chosen as requested.
    Variables and methods   : a
ay                                         -> the two dimensional a
ay
                              n,m                                           -> size of the a
ay
                              low, high                                     -> range of initialization values
                              createA
ay(int m, int n, int low, int high)  -> function used to create a
ay
                              printA
ay(double[][] a
ay)                  -> function used to print A
ay
 *
*
    Test Plan               : There is no input required for this program as the range is hardcoded.
                              For loop in printA
ay() method can be enhanced.
                              Run the application
                              Expected :
                                        Test A
ay 1
                                        ------------
                                        87.69427328589698 40.0043892611327 26.741179079648603 41.361263997571584 7.721971324908205
                                        40.51549115713916 45.11138681973026 2.920162341507692 82.23870377244268 79.12850662424718
                                        59.89546188006628 88.66611225486925 91.09308695500822 52.86082912825818 42.389368898221605
                                        42.93914408970441 84.7579085289062 19.607281808096275 85.6299518958369 6.354349601506614
                                        54.52811278821581 44.53489276641034 65.23437026064119 21.663271259569104 71.85037009396594
                                        ------------
                                        Test A
ay 2
                                        ------------
                                        43.25044553792696 21.9470882366046 18.731311142610515 38.892638781506776 22.294251333685224 29.41947607455076 35.02373349535348
                                        29.470934010549303 37.20926809740068 21.84913829174079 40.91065610028764 35.41050635872225 43.61820279290778 19.393508690322484
                                        10.224428678188001 49.52286056743369 21.523023457982962 26.267252544699495 15.747784531137476 47.297763484262404 48.260300963167374
                                        ------------
                                        Test A
ay 3
                                        ------------
                                        4.951672211468216 1.1410399986061106
                                        5.495745299975068 2.228241772800856
                                        3.8280325834086613 1.4715650271870253
                                        4.380951967594444 2.676473650400488
                                        1.3167783146062308 3.68385741292467
                                        4.395385868704134 1.9019160885294757
                                        1.2414912111306022 4.975478959882613
                                        5.094058992053861 4.3866345068233255
                                        1.2172295142154546 2.482744519359931
                                        1.5098771234821915 1.8213391610063132
                                Actual :
                                        Results displayed as expected
 *
import java.lang.Math;
public class Assignment1Question3 {
    public static void main(String[] args) {
        System.out.println("Test A
ay 1");
        System.out.println("------------");
        
 Create a
ay with size 5x5 and initialization values from 1 to 100
        double[][] a
ay1 = createA
ay(5,5,1,100);
        printA
ay(a
ay1);
        System.out.println("------------");
        System.out.println("Test A
ay 2");
        System.out.println("------------");
        
 Create a
ay with size 3x7 and initialization values from 10 to 50
        double[][] a
ay2 = createA
ay(3,7,10,50);
        printA
ay(a
ay2);
        System.out.println("------------");
        System.out.println("Test A
ay 3");
        System.out.println("------------");
        
 Create a
ay with size 10x2 and initialization values from 1 to 5
        double[][] a
ay3 = createA
ay(10,2,1,5);
        printA
ay(a
ay3);
    }
    public static double[][] createA
ay(int m, int n, int low, int high){
        
 a
ay initialization
        double[][] a
ay = new double[m][n];
        for(int i=0;i            for(int j=0;j                
 setting values to given a
ay in the range of initialization values
                a
ay[i][j] = low + (double)(Math.random() * ((high - low) + 1));
            }
        }
        return a
ay;
    }
    public static void printA
ay(double[][] a
ay){
        
 row length
        int m = a
ay.length;
        
 column length
        int n = a
ay[0].length;
        
 Iterate for each cell and print it's value
        for(int i=0;i            for(int j=0;j                System.out.print(a
ay[i][j]+" ");
            }
            
 Go to a new line after a row is completed
            System.out.println();
        }
    }
}
JavaAssingment/Assignment1Question2.java
JavaAssingment/Assignment1Question2.java
*
    Name                    :
    Student ID              :
    Date                    :
    Assignment Number       : 1
    Program Name            : Assignment1Question2
    Program Description     : Print prime numbers in given range
 *
*
    DOCUMENTATION...
 *
*
    Program Purpose         : This program generates prime numbers in given range using nested for loop and modulo operator.
    Extra Requirements      : Nil
    Compile                 : javac Assignment1Question2.java
    Run                     : java Assignment1Question2
    Class name              : Assignment1Question2, chosen as requested.
    Variables               : check -> boolean, used to check if number is prime or not
                              val   -> used to aid in pretty print as requested
 *
*
    Test Plan               : There is no input required for this program as the range is hardcoded.
                              Run the application
                              Expected :
                                        2  3  5  7  11  13  17  19  23  29
                                        31  37  41  43  47  53  59  61  67  71
                                        73  79  83  89  97  101  103  107  109  113
                                        127  131  137  139  149  151  157  163  167  173
                                        179  181  191  193  197  199  211  223  227  229
                                        233  239  241  251  257  263  269  271  277  281
                                        283  293  307  311  313  317  331  337  347  349
                                        353  359  367  373  379  383  389  397  401  409
                                        419  421  431  433  439  443  449  457  461  463
                                        467  479  487  491  499  503  509  521  523  541
                                        547  557  563  569  571  577  587  593  599  601
                                        607  613  617  619  631  641  643  647  653  659
                                        661  673  677  683  691  701  709  719  727  733
                                        739  743  751  757  761  769  773  787  797  809
                                        811  821  823  827  829  839  853  857  859  863
                                        877  881  883  887  907  911  919  929  937  941
                                        947  953  967  971  977  983  991  997  1009  1013
                                        1019  1021  1031  1033  1039  1049  1051  1061  1063  1069
                                        1087  1091  1093  1097  1103  1109  1117  1123  1129  1151
                                        1153  1163  1171  1181  1187  1193  1201  1213  1217  1223
                                        1229  1231  1237  1249  1259  1277  1279  1283  1289  1291
                                        1297  1301  1303  1307  1319  1321  1327  1361  1367  1373
                                        1381  1399  1409  1423  1427  1429  1433  1439  1447  1451
                                        1453  1459  1471  1481  1483  1487  1489  1493  1499  1511
                                        1523  1531  1543  1549  1553  1559  1567  1571  1579  1583
                                        1597  1601  1607  1609  1613  1619  1621  1627  1637  1657
                                        1663  1667  1669  1693  1697  1699  1709  1721  1723  1733
                                        1741  1747  1753  1759  1777  1783  1787  1789  1801  1811
                                        1823  1831  1847  1861  1867  1871  1873  1877  1879  1889
                                        1901  1907  1913  1931  1933  1949  1951  1973  1979  1987
                                        1993  1997  1999  2003  2011  2017  2027  2029  2039  2053
                                        2063  2069  2081  2083  2087  2089  2099  2111  2113  2129
                                        2131  2137  2141  2143  2153  2161  2179  2203  2207  2213
                                        2221  2237 ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here