Assignment 1 Due: A Java Programming Warm-up This assignment is…

| January 23, 2015

This assignment is intended to warm up your Java by macvx”>PROGRAMMING skills. It does not exercise any object-oriented programming concepts. You can (and should) simply use static public class functions and local variables. It will, however, exercise basic programming constructs such as loops and conditional execution and require you to use arrays.

The assignment is in three parts that are in increasing level of difficulty called A1Novice, A1Adept, and A1Jedi. The basic idea for all of the parts is to write a program that processes a set of “rectangles”. In one of the parts, we will also process a set of “points” along with a set of rectangles. Each of the parts is more completely described below.

In all three parts, I will provide a class with a main method that creates an input Scanner object (the use of which will be demonstrated in class and described below) and then calls the method process, providing the Scanner object as a parameter.

You are responsible, in each case, for implementing the process method as described below for each part and produce output usingSystem.out.println(). Please match the format of the example output provided and do not produce any additional output. You are by macvx”>FREE TO(and in fact encouraged to) create additional class methods to use as helper functions as you see fit (although each part can be done easily without having to create any additional methods).

The set up directions below assume you are using Eclipse. You are not required to but you do need to use the same package and class names. Remember, capitalization counts.


This assignment requires you to make use of a Scanner object. You can read the documentation for the Scanner object here. A Scanner object is associated with a source of input. In our case, this will be keyboard input from the console. By default, Scanner will parse the input as whitespace separated tokens and have methods for parsing the next available token as a particular type. The method next() will retrieve the next token as a String. The method nextInt() will retrieve the next token as an integer. For this assignment, you shouldn’t have to use any Scanner methods other than next() and nextInt(). You do need to call the correct method depending on what you expect from the input. For example if you callnextInt() but the next input can not be interpreted as an integer, this will cause an error. For this assignment, you can assume that the input will always be valid and conform to the description below. In other words, you do not have to worry about validating the input or being able to deal with unexpected input.

Set Up

To set up the assignment, create a new project in Eclipse called “Assignment1”.

In the project, create a package called “a1”. Be very sure to call your package “a1” and NOT “A1”, “Assignment1”, “HW1”, or anything else other than “a1”. I can not stress how important it is that you be sure that your package name is “a1”.

In the package, create three classes called, “A1Novice”, “A1Adept”, and “A1Jedi”. Again, it is very important that you use these class names exactly.

Add the following line to the top of each class file after the package declaration:

import java.util.Scanner;

Edit the contents of each class to look like this:

public static void main(String[] args) { Scanner s = new Scanner(; process(s); } public static void process(Scanner s) { /* Here is where your code will go. */ }

For each part described below, your code should go in the body ofprocess. You should not editmain(). The above code will set up the Scanner object s passed to process to retrieve keyboard input from the console and will be ready for use by your code. Within process, to use the Scanner object s, simply call the appropriate method of s. For example, the expression s.nextInt() would ask the Scanner object s to retrieve the next input as an integer and return it.


This by macvx”>PROGRAM should process the input as a sequence of labeled rectangles. The first word of input will be a positive integer number indicating how many labeled rectangles follow. Following this will be a description of each labeled rectangle comprised of a single word string label followed by 4 integers that define the x and y coordinates of two opposing corners of the rectangle.

For example, given the following input:

3 A 0 0 10 10 B -5 -2 7 7 C 6 5 3 2

Your program would first read in the value 3 as an integer in order to understand that 3 rectangle definitions will follow. The first rectangle is labeled “A” and is defined by the two points (0,0) and (10,10). The second rectangle is labeled “B” and is defined by the two points (-5,-2) and (7,7). The last rectangel is labeled “C” and is defined by the two points (6,5) and (3,2).

Each rectangle will be defined by two points that represent opposing corners, but this may either by the upper left and lower right corner or lower left and upper right corner.

All coordinates will be given as integers (possibly negative) and all rectangles will be valid (i.e., will have a non-zero width and height). You do NOT have to worry about illegal or invalid input.

Your program should read and process this input in order to calculate and report:

  • The number of rectangles that were square.
  • The number of rectangles that were wider than they were tall.
  • The number of rectangles that were taller than they were wide.
  • The rectangle with the minimum perimeter.
  • The rectangle with the maximum perimeter.
  • The rectangle with the minimum area.
  • The rectangle with the maximum area.

For example, given the input above, your solution should produce the following output:

Square count = 2 Wide count = 1 Tall count = 0 Min perimeter = 12 (C) Max perimeter = 42 (B) Min area = 9 (C) Max area = 108 (B)

If more than one rectangle qualifies as the min/max perimeter/area, your by macvx”>PROGRAM should report the first rectangle entered.

Your program should match the format of the output as shown above (obviously with different actual counts, min/max perimeter/area, and labels as appropriate for the input).

For this program, you should NOT need to store the rectangles in an array or any other sort of collection. This program should be able to process the input one rectangle at a time, keeping track of the results are it goes along and then reporting them once all of the input has been processed.


In this version of the program, the input list of rectangles will be followed by a list of points. Your program should report for each labeled rectangle, how many of the points are contained inside the rectangle. A point is contained within a rectangle only if it is strictly inside the rectangle (i.e., not on an edge).

The input will be comprised of an integer indicating the nubmer of rectangles, followed by the description of each rectangle as above (i.e., a single word label followed by two x,y coordinates for opposing corners), followed by an integer indicating the number of points, followed by that many x,y pairs defining each point. Note that the points are not labeled.

For example, given the following input:

4 A 0 0 10 10 B -5 -2 7 7 C 6 5 3 2 D 15 15 20 30 5 1 1 17 30 -3 -1 4 3 7 7

Your by macvx”>PROGRAM should understand this input as defining 4 labeled rectangles followed by 5 points and produce the following output:

A contains 3 points B contains 3 points C contains 1 points D contains 0 points

Again, be sure to match the formatting of the output as above. Note that the point (7,7) is NOT contained in rectangle B because the point is on the edge of that rectangle and is not strictly within the rectangle. The same is true, for example, of the point (17,30) which is on the edge of rectangle D. Also note that the same point might be included within more than one rectangle.

This program will require the use of arrays. In particular, you will need to store the information used to define each rectangle so that you can compare each point against each rectangle. You will also need an array of counts associated with each rectangle that you can update as you discover which points are within which rectangles.


In this version of the program, you will report on which rectangles intersect with which other rectangles.

The input will again be an integer count of the number of rectangles followed by descriptions of each rectangle comprised of a single word string label and then the x,y coordinates to two opposing points.

So, given the following input:

5 A 0 0 10 10 B -5 -2 7 7 C 6 5 3 2 D 15 15 20 30 E 16 15 18 10

Your program should produce the following output:

A intersects B C B intersects A C C intersects A B D intersects nothing E intersects nothing

Rectangles that simply abut (i.e., share part of an edge or corner) do NOT intersect.

Again, please match the formatting above. In particular, start each line with the label of each rectangle in the order that they were provided in the input followed by the word “intersects” and then a space separated list of the rectangle labels of any intersecting rectangles listed in order relative to the input. If a rectangle does not intersect anything, use the word “nothing”. Do not include any other output and/or punctuation.

Submitting your code

Get a 5 % discount on an order above $ 150
Use the following coupon code :
This PROGRAM should process the input as a sequence of labeled rectangles. The first word of...

Category: Essay Topics

Our Services:
Order a customized paper today!
Open chat
Hello, we are here to help with your assignments