1)- DrawX We are going to create a method that fills a 2-dimensional char array with a pattern that will print an "X". Starter Code /** * A class that generates a 2-D char array representing an 'X' *...

1 answer below »
1)-

DrawX


We are going to create a method that fills a 2-dimensional char array with a pattern that will print an "X".


Starter Code


/**
* A class that generates a 2-D char array representing an 'X'
*
*

Purdue University -- CS18000 -- Summer 2021



*
* @author Purdue CS

* @version June 14, 2021
*/
public class DrawX {
private int size;

public DrawX(int size) {
this.size = size;

}
public char[][] generateArray() {
char[][] xArray = new char[size][size];

// TODO
return xArray;

}
}

The Starter Code for this assignment sets up a class for your use.




Exercise


Open theDrawX.javafile in the editor of your choice.



Input


Input will be passed in the form of an int used in the constructor. The integer will then be used to initialize an array of the appropriate size.



Processing


You will need to store the appropriate characters in each element of the array. The formula for the 'X' is as follows:



  • Elements at index positions where each index is the same should be given a value of '*'.

    • For example, [0][0],[1][1], and so on. This covers the first diagonal line we need to create.



  • The second diagonal can be created by storing '*' in the positions where both indexes add up to the size field's current value minus one.

    • For example, if the size is 5, the elements would be [0][4], [1][3], [2][2], [3][1], and [4][0].



  • Every other element should be ' ' (a space). This will ensure the array prints correctly.



Output


There will be no output for this walkthrough. The method will return the properly formatted array.


Testing


For the walkthrough, we are going to utilize Output Testing. Create a main method for the class and create DrawX objects with various sizes, then print the arrays. We've included a simple main method and several example runs below. Use them to verify that your program is working as expected.



public static void main(String[] args) {
DrawX sample = new DrawX(3);

char[][] testArray = sample.generateArray();

for (int i = 0; i

System.out.println(Arrays.toString(testArray[i]));
}
}


Note: Here, we use the ArraystoString()method on an array (you will need to importimport java.util.Arrays;for it to work). This will print a String representation of each element of the array. Notice that we do not use it on the entire 2-dimension array, only one of the sub-arrays. Try doing so and see what happens.





Test 1 (size = 3)


[*,  , *]
[ , *, ]
[*, , *]


Test 2 (size = 5)


[*,  ,  ,  , *]
[ , *, , *, ]
[ , , *, , ]
[ , *, , *, ]
[*, , , , *]


Test 3 (size = 10)


[*,  ,  ,  ,  ,  ,  ,  ,  , *]
[ , *, , , , , , , *, ]
[ , , *, , , , , *, , ]
[ , , , *, , , *, , , ]
[ , , , , *, *, , , , ]
[ , , , , *, *, , , , ]
[ , , , *, , , *, , , ]
[ , , *, , , , , *, , ]
[ , *, , , , , , , *, ]
[*, , , , , , , , , *]


Test the program with other sizes. Does it work as expected? If so, you're done!


Submit


Now that the program is in working order, we can submit it using the Submit button on Vocareum. Vocareum will run your code with a few test cases to make sure it is working properly. Once you receive a 5/5, the Debugging exercise will unlock.


2)-


For this assignment, we will be using a Javadoc. A Javadoc is generated usingformatted comments to create an HTML page. You've probably seen the official documentation already!



The implementation instructions for this assignment are available in the Javadochere. Be sure to follow the instructions listed for each class.



It is recommended that you start with implementingVideofirst, followed byChanneland thenProfile.




Hint:String.format()allows you to easily format a string with input values. This may help you while implementing methods such astoString().


For example,String.format("Student[Name=%s, Age=%d, GPA="%.2f]"), "Jack", 19, 3.3)will return the stringStudent[Name=Jack, Age=19, GPA=3.30].




Testing


We have included a program that will allow you to create and run output tests automatically in the Starter Code. This will make it easier for you to verify that each possible progression through your solution is correct. Take a look atRunLocalTest.java. There are many utility features and tools that you do not need to worry about at the moment, instead, focus on the test case. It is included in the Starter Code. Read through it.



You can modify the test to test any method you like by following the same format. You can either download the program and run the main method or use the "Run" button on Vocareum to run the test. You can repeat this process for each path.




Public Test Cases Note


For many homeworks and projects, we will give you test cases that correspond to several of the ways we will be testing your program. But, we will not give you test cases for ALL of the ways we will be testing your program. You should think of other test cases to use that will fully test every aspect of every feature of your program. Just because your program passes all the test cases we give you does not mean that it is fully correct and will receive a score of 100.




Submit


After testing your solution and verifying that it meets the requirements described in this document, you can submit on Vocareum. You have 10 submission attempts to achieve full points.


Starter code-


/**


* Homework 7 - Channel


*



* The Channel class represents details about a content uploader.


* This includes their channel name, subscribers, an array of Video


* objects created by them, and the number of uploads.


*/


public class Channel {



/**



* Name of the channel



*/



private final String channelName;



/**



* Number of subscribers of this channel



*/



private int channelSubscribers;



/**



* Number of videos uploaded by this channel. This may be of use when iterating through the videos array.



*/



private int numUploads;



/**



* An array containing videos uploaded by this creator.



*/



private Video[] videos;


}






Answered 1 days AfterOct 08, 2021

Answer To: 1)- DrawX We are going to create a method that fills a 2-dimensional char array with a pattern that...

Kshitij answered on Oct 09 2021
141 Votes
Channel.java
Channel.java
/*   Created by IntelliJ IDEA.
 *   Author: Kshitij Varshney (kshitijva
rshne1)
 *   Date: 10-Oct-21
 *   Time: 9:25 AM
 *   File: Channel.java
 */
package October.oct09_21;
import java.util.Arrays;
public class Channel {
    /**
     * Name of the channel
     */
    private final String channelName;
    /**
     * Number of subscribers of this channel
     */
    private int channelSubscribers;
    /**
     * Number of videos uploaded by this channel. This may be of use when iterating through the videos array.
     */
    private int numUploads;
    /**
     * An array containing videos uploaded by this creator.
     */
    private Video[] videos;
    public Channel(String channelName, int channelSubscribers, int numUploads, Video[] videos) {
        this.channelName = channelName;
        this.channelSubscribers = channelSubscribers;
        this.numUploads = numUploads;
        this.videos = videos;
    }
    public String getC...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here