, Page 1 of 6 School of Science COSC2531 Programming Fundamentals Assignment 1 Assessment Type: Individual assignment; no group work. Submit online via Canvas → Assignments → Assignment 1. Marks...

1 answer below »
need to know about payment


, Page 1 of 6 School of Science COSC2531 Programming Fundamentals Assignment 1 Assessment Type: Individual assignment; no group work. Submit online via Canvas → Assignments → Assignment 1. Marks awarded for meeting requirements as closely as possible. Clarifications/updates may be made via announcements/relevant discussion forums. Due date: end of Week 6; Deadlines will not be advanced but they may be extended. Please check Canvas → Assignments → Assignment 1 for the most up to date information. As this is a major assignment, a university standard late penalty of 10% per each working day applies for up to 5 working days late, unless special consideration has been granted. Weighting: 10 marks out of 100 1. Overview The objective of this assignment is to develop your programming and problem solving skills in a step- by-step manner. The different stages of this assignment are designed to gradually introduce different concepts, such as loops, arrays, and methods. Students may be awarded partial marks for explaining a valid strategy, even if the program is not working. Develop this assignment in an iterative fashion (as opposed to completing it in one sitting). You can and should get started now as there are concepts from the week 1 lessons that you can incorporate from now itself. If there are questions, you must ask via the relevant Canvas discussion forums in a general manner (replicate your problem in a different context in isolation before posting). 2. Assessment Criteria This assessment will determine your ability to: 1. Follow coding, convention and behavioral requirements provided in this document and in the lessons. 2. Independently solve a problem by using programming concepts taught over the first several weeks of the course. 3. Write and debug Java code independently. 4. Document code. 5. Ability to provide references where due. 6. Meeting deadlines. 7. Seeking clarification from your “supervisor” (instructor) when needed via discussion forums. , Page 2 of 6 8. Create a program by recalling concepts taught in class, understanding and applying concepts relevant to solution, analysing components of the problem, evaluating different approaches. 3. Learning Outcomes This assessment is relevant to the following Learning Outcomes: 1. Demonstrate knowledge of basic concepts, syntax and control structures in programming 2. Devise solutions to simple computing problems under specific requirements 3. Encode the devised solutions into computer programs and test the programs on a computer 4. Demonstrate understanding of standard coding conventions and ethical considerations in programming. 4. Assessment details Note: Please ensure that you have read sections 1-3 of this document before going further. Your code must meet the following code and documentation requirements. MyBlock is a simple tool which can help one design a block of land. Your task is to write a Java program that implements the design functionality, checks if all the rules are followed, displays the block. The basic structure of the code is provided in the Canvas shell. You need to complete the following tasks. Please use the skeleton code provided to complete your code. Your program should consist of a MyBlock class. The class has a two dimensional array of integers called block. The class also has a Boolean variable vacant that stores the information of whether the block of land is vacant or not. The methods of this class are: displayBlock(), addHouse(), and clearBlock(). Task A The constructor of the MyBlock class takes 2 parameters: the number of rows of the block, the number of columns of the block. In the constructor of this class, write code to initialize the block with the size of row and column. Initialize each value of the array block with the value 0, which means that block is unused. Initialize the value of vacant to true. Task B Write a method of the MyBlock class called displayBlock() that prints the block as a two dimensional array. Give a space between each element during printing, and use a line for each row. An example of the output of displayBlock()is shown below, for a vacant block of 3 x 4 (row x column). 0 0 0 0 0 0 0 0 0 0 0 0 Task C Write a method of the MyBlock class called clearBlock()that sets the value of each element of the array ‘block’ to zero (0). Set the value of vacant to true. , Page 3 of 6 Task D From the main method, the user can enter the row and column of the block. The number of rows and the number of columns should be an integer greater than 2 and less than or equal to 10. If any input is incorrect, show an error message and ask for that input again. If all inputs are correct, create an object of MyBlock class from main method. The row and column values are passed as the parameter of its constructor. Task E From the main method, show a menu to the user with the following options. If the input is neither 1,2,3,4, show an error message and ask the user for input again. 1. Add a house 2. Display the block 3. Clear the block 4. Quit Option 1 – Add a house It prompts the user of the position of the house (x, y) and the number of rows and columns of the house and then call the addHouse() method of the MyBlock class with those values as parameters (in the order of x, y, row, column). Implementing the addHouse() method is a separate task detailed in Task F. If a house cannot be added, show error then back to the menu. Option 2 – Display the block Call the displayBlock() method. Option 3 – Clear the block Call the clearBlock()method. Option 4 - Quit If the input is 4, terminate the program. Task F Implements the addHouse() method that takes four input parameters: the row position, the column position, the number of rows, and the number of columns of the house. Parameters row position and column position are the house’s top left corner position. For example (2, 1) means the house starts from 2 rows down from the top and 1 column from the left edge of the block. This method must observe the follow rules: Rule 1: If the block is empty, a house can be anywhere in the block, but not touching the edges. That means there needs to be at least one row and one column gap between the house and the four sides of the block. For example, the largest possible house in a 5 x 7 block is of size 3 x 5, with a top-left corner position (1, 1) (see below). 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 (VALID) 0 0 0 0 0 0 0 (INVALID) , Page 4 of 6 Rule 2: If there is already a house or houses in the block, the new house must be one row or one column away, yet still observing Rule 1 (see below). 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 2 2 0 0 1 1 0 2 2 0 0 1 1 1 2 2 0 0 0 0 0 2 2 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 (VALID) 0 0 0 0 0 0 0 (INVALID) Rule 3: No part of a house can go outside of the block. Rule 4: The smallest house size is 1 x 1. You may represent all houses with ‘1’ (No mark deduction). You can also take a challenge: representing the first house with ‘1’, the second with ‘2’, the third with ‘3’ and so on. If any of the rules is violated, the addHouse method should return with no house added. Consider where and how an error message should be showed to user. You may discuss that in comments. If no rule is violated, the addHouse method should change the values in the block array for the house(s). The value of vacant should be correct. After building the house, call displayBlock() from the addHouse method to show the updated block. The following code requirements must be applied in a fashion similar to what has been shown in lesson materials. The program must be entirely in one Java class/file ProgFunAssignment1.java. Other names will not be accepted. Code formatted consistently. Tip: you would use Eclipse→Source menu→Format before every submission. Must not include any unused/irrelevant code (even inside comments); what is submitted must be considered the final product. Use appropriate data types and handle user inputs properly e.g. using Scanner. Must not have redundant conditions/parts in else if statements No ArrayList or similar data structures in Assignment 1. Students must demonstrate their ability to manipulate (standard) Java arrays on their
Answered Same DayApr 18, 2021COSC2531

Answer To: , Page 1 of 6 School of Science COSC2531 Programming Fundamentals Assignment 1 Assessment Type:...

Aditya answered on Apr 20 2021
152 Votes
// import whatever packages are needed here
package progfunassingment1;
import java.util.Scanner;
public class ProgFunAssingment1 {
public static void main(String[] args) {
int userInputRow;
int userInputColumn;
int userInput;
Boolean house
Build;
// Create a Scanner object for input
Scanner sc = new Scanner(System.in);
System.out.println("Enter The Number Of Rows");
while(true)
{
userInputRow = sc.nextInt();
if((userInputRow>2)&&(userInputRow<=10))
{
break;
}
System.out.println("Wrong Input Value Please Enter the Number Of Rows between 2 and 10");
}
System.out.println("Enter The Number Of Column");
while(true)
{

userInputColumn = sc.nextInt();
if((userInputColumn>2)&&(userInputColumn<=10))
{
break;
}
System.out.println("Wrong Input Value Please Enter the Number Of Columns between 2 and 10");
}

// Create an object of class MyBlock using the 'new' operator, calling on the MyBlock constructor.
MyBlock obj = new MyBlock(userInputRow,userInputColumn);

// Build a loop to display the menu, prompt for input and process it as per requirements.
do
{
System.out.println("1. Add a house");
System.out.println("2. Display the block");
System.out.println("3. Clear the block");
System.out.println("4. Quit");
userInput = sc.nextInt();
switch(userInput)
{
case 1:
{
System.out.println("Enter The Row Position");
int rowPos = sc.nextInt();
System.out.println("Enter The Column Position");
int columnPos = sc.nextInt();
System.out.println("Enter The Rows");
int rows = sc.nextInt();
System.out.println("Enter The Columns");
int columns = sc.nextInt();
houseBuild = obj.addHouse(rowPos, columnPos, rows, columns);
if(houseBuild == true)
{
obj.displayBlock();
}
else
{
System.out.println("No House Has Been Added");
}
continue;
}
case 2:
{
obj.displayBlock();
continue;
}
case 3:
{
obj.clearBlock();
continue;
}
case 4:
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here