Critical Assignment Instructions and Recommendations

Important assignment points:

  • Read entire assignment, pay close attention to input/output specification. If you have problems completing assignment, consult hints.
  • Submit is used to , grade assignments, If you need to submit assignments more than 3 times, contact me, you have not learned how to follow specifications yet. This is a very important skill to learn, Learning how to extract critical information from your environment is not innate it is a skill you develop. All modern day large system are based on multiple components meeting I/O specifications.
  • Document your program by using a standard header comment that clearly defines the assignment objectives, input and output specificatins, you can lose points by not documenting/commenting your progam.
  • In comment header include specific input/output specifications. Nota bene, submit requires you to meet input/output specifications.
  • Assignments are due by dates specified on submit, you have a 7 day grace period with a 20-25% penalty, after 7 days its a 50% penalty.

Intro Orientation (aka H0) End of First Week of Class

Complete the five steps at

Web-cast:2 Orientation its is on Canvas under videos/Web-casts.


Submit Filename:

Submit Filename:

Your text-book has video notes access on behind front cover, consider using this.

NetBeans Install Process (You may use any IDE but only NetBeans will be covered)

Consult Canvas Netbeans 11.2 discussion board (part of quiz 0 start here) .

  1. NetBeans/Java requires a 64bit install - how to check if you have 32 bit or 64 bit OS Install
  2. First  install recent Oracle JDK, reboot your system
  3. Download the latest NetBeans Apache 11.2 exe installer file

In modern programming specifications matter! Modern day systems have become multiple programs, that must meet a strict Input/Output specification. Multiple applications/programs work together because they all communicate using a strict input/output specifications. The browser you are currently using is actually multiple programs. It includes both a JavaScript and rendering engine. For submitting assignments you need to learn how to follow input/output specifications. This is relatively easy if you follow the following steps...

  1. First Identify the class and file name, in Java these are the same.
  2. Second clearly identify your input specification, what is the type and format of input. Most input is just free form data. Free form data is just white space separated data.
  3. Third determine output specifications
  4. Determine logic required to convert input to output, Note you have to understand what logic is required for each assignment. Write up your logic in plain English. If you know flowing charting or UML you may use that. The goal is first put the logic in a language which is easy for you to understand. Then translate it to Java. You must identify all 4 steps in your comment header. For the comment header would look like...


Class Name: Hello7B
File Name:

Input: None
Logic: Program just outputs three lines of text. Note second line starts with a tab.
Output: Hello CIMP7B\n\tSpecifications matter this is how new cars\ncan have multiple interfaces to the same LCD display.\n

@author Joe Student Spring 2020


Sample Run (no Input )

Hello CIMP7B
        Specifications matter this is how new cars
can have multiple interfaces to the same LCD display.

Watch the History of Java Video and may want to take a look Java SE9

Complete Canvas intro Quiz and attend or watch first Web-cast.

Optional first page of book has access to video notes, you can wait to set this up.


  • Watch or attend Orientation Intro Web-Cast
  • Install a NetBeans or Equivalent Java IDE
  • submit
  • Complete Canvas Intro Quiz
  • Complete Questionnaire
  • Complete Canvas discussion board on why are Java and C dominating?

You may also want to review the CIM site policy.


Determine the difference between: System.out.println( "Hello\n" ) versus System.out.print( "Hello\n"); versus System.out.println( "Hello" );

Consistency checks:

  • In Java class name and file name must always match, for this assignment class is Hello, file name is
  • Output is almost always new line terminated, ends in a single new line (aka \n).


submit Filename: and

Submit Filename: (Ninth Edition Page 31 1.4 Modified; 10th Edition Page 30 1.4)
Submit Filename: (Ninth Edition Page 32 1.11 Modified; 10th Edition Page 31 1.11)

Study/Read chapter 1 and take Canvas chapter 1 quiz. Specifications.
Output the integer numbers 1..10 with their square and cube (all numbers are integers). Fields are tab separated, each row ends in newline. First line is the string "A\tA^2\tA^3\n".

A	A^2	A^3
1	1	1
2	4	8
3	9	27
... A is up to and including 10 - Minor Changes Read Description...

"The U. S. Census Bureau projects population based on the following assumptions:

  • One birth every 7 seconds
  • One death every 13 seconds
  • One new immigrant every 45 seconds

Write a program to display the population for each of the next 20 years (starting at 2012 up to including 2031). Assume the current population for US is 312,032,486, for Saddleback College 2012 enrollment was about 26,000. Assume Each year will have exactly 365 days (ignore leap years). Hint: In Java, if two integers perform division, the result is an integer. The fraction part is truncated. For example, 5 / 4 is 1 ( not 1.25) and 10 / 4 is 2 ( not 2.5).". All numbers and calculations are in floating point double precision, when you print out populations typecast to int.

Your program should about three columns of data, first column is year, second is Saddleback population, third is US population. First Line is "Year\tSaddleback\tUS\n". Once again fields are tab separated, each row is newline terminated. First two rows are...

Year    Saddleback      US
2012 26000 312032486
2013 26231 314812582
2014 26463 317592679
2015 26694 320372776

Assume population increase per year will remain constant, (no compounding); also assume that the initial population increase for SB, will be based on the US Census bureau data but will be scaled to reflect the 2012 population ratio of us to saddleback. For example calculate the population increase per year for the US, then multiple this increase by the ratio of the 2012 SB to US population. Print out all populations as int, but do all calculations using double. We will use System.out.println( ... "\t" + (int)usPopulation + ... ) or
System.out.printf( "%d" , ..., (int)usPopulation). All programs must include a comment header detailing input/output specifications and logic used to convert input to output. For these two programs the input is internal to the program 1..10 in the first case, 1..20 in the second case.


  • Except year, all variables are double, all calculations are double. Typecast double to int before printing.
  • Gain for population is a constant value calculated from birthrate, deatth rate and immigration rate.
  • Population increase for SB is just the US gain times 2012 ratio of SB population to US population. Note in reality Orange County actually has a slower birthrate than rest of US, but not for this assignment.

Nota Bene, these programs are review, but the second program will require some thought. If you have problems with the logic on population, then you may want to think about it before going to sleep, when you awake you may be able to write down the solution.

Consistency Note

  • All input is from standard in,
  • All output is to standard output, System.out
  • Only exception is when we cover File I/O in later chapters
  • When we do calculations they are always double, unless specified otherwise.


  • Submit Filename: (Ninth Edition Page 31 1.4 Modified)
  • Submit Filename: (Ninth Edition Page 32 1.11 Modified)
  • Complete Canvas Chapter 1-3 review Quiz

submit (10th edition page 74 Exercise2_23)

Submit Filename: (10th Edition Page 74 2.23)

From Page 74 "(Cost of driving)Write a program that prompts the user to enter driving distance, miles per gallon and price per gallon, display the total cost of the trip".

Sample Run (user enters 900.5, 25.5 and 3.55)...

Enter the driving distance: 900.5
Enter miles per gallon: 25.5
Enter price per gallon: 3.55
The cost of driving is $125.36

Second Sample Run (user enters 1000.55 24 1.567 all on one line)

Enter the driving distance: 1000.55 24 1.567
Enter miles per gallon: Enter price per gallon: The cost of driving is $65.33
BUILD SUCCESSFUL (total time: 18 seconds)

Third Same Run Scanner Input set to new Scanner( "100 25.5 2.34");

Enter the driving distance: Enter miles per gallon: Enter price per gallon: The cost of driving is $9.18
BUILD SUCCESSFUL (total time: 0 seconds)


Use formatter for output, we want only two decimal point precision and comma every third digit left of decimal point. Output code is...

System.out.format( "... driving is $%,.2f\n", cost );

Consistency Notes:

  1. Whenever we have a prompt it ends in : colon space, you have a space after the colon no space before colon.
  2. We don't end prompts with a newline, but in the first test case the user is entering numbers for each prompt.
  3. Unless otherwise specfied all input is free form format, that is white space delimited data, just ust nextDouble( );.
  4. Whenever we have calculations that are mixed types (i.e., float, int and/or double), declarations and calculations will be type double. Note in java.lang.Math almost all methods return and deal only with type double.
  5. Almost all double output uses format specifier ,.2f, or $%,.02f for Currency. Note , comma adds a comma every third digit, . dot represents precision, %.02f means fill missing output right of decimal point with Zeros.


  • Submit Filename: (10th Edition Page 74 2.23)
  • Review Chapter 2 and 3 and take chapter 1-3 review quiz a second time Canvas Quiz
  • On Submit, click the grades tab and verify grade table has recorded your assignment grades.

submit Filename: (10th Edition page 110 3.11)

Submit Filename: (10th Edition Page 110 3.11)

"Write a program that Prompts the use to enter month then year, and responds with number of days in that month"

Sample Run (2 2012)

Enter month then year: 2 2012
Days in February 2012 is 29

Sample Run 2 (user enters 3 2015)

Enter month then year: 3 2015
Days in March 2015 is 31

Enter month then year: 2 2100
Days in February 2100 is 28
BUILD SUCCESSFUL (total time: 3 seconds)

Enter month then year: 2 2000
Days in February 2000 is 29
BUILD SUCCESSFUL (total time: 5 seconds)

Enter month then year: 4 23000
Days in April 23000 is 30
BUILD SUCCESSFUL (total time: 5 seconds)


  • 30 days hath September, April, June and November. All the rest 31 except February 28 days and 29 in leap years.
  • Leap year, divisible by 4 and not 100 or divisible by 400.

Consistency Note

  • All input is free form, it is white space separator, don't use nextLine use nextInt.
  • We always end the final line of output with a new line.


  • Submit Filename: (Ninth Edition Page 78 modified)
  • Review Chapter 4 and take Chapter 4-6 Canvas Quiz the first time.
  • Click the last tab on submit, to check to make sure all your submitted assignments have been recorded.
  • Verify you have completed the first 4 quizzes, click on Canvas quiz grades tab.

submit (10th 5.30 page 197) (Loops)

Chapter 4 in the 10th Edition, will be covered Later on.

Submit (Ninth Edition page 172; 10th Edition Page 197 5.30)

"( Financial application: compound value) Suppose you save $100.0 each month into a savings account with the annual interest rate 5.0%. So, the monthly interest rate is 0.05 / 12 = 0.00417.

After the first month, the value in the account becomes 100.0 * ( 1 + 0.00417) = 100.417

After the second month, the value in the account becomes ( 100.0 + 100.417) * ( 1 + 0.00417) = 201.252

After the third month, the value in the account becomes ( 100.0 + 201.252) * ( 1 + 0.00417) = 302.507 and so on.

Write a program that prompts the user to enter an amount ( e. g., 100.0), the annual interest rate ( e. g., 5), and the number of months (e.g., 6) and displays the amount in the savings account after the given month.

Input: (3 Numbers on one line white space delimited)
Amount, Annual Interest Rate and Number of Months, amount and annual interesting are floating point (aka double), number of months is a whole number (aka integer)

Output: (Prompt and Final Value)

Enter initial amount, annual interest rate and number of months: 100 0.05 3
After 3 months you will have $302.51

Note 100 0.05 and 3 are the three input values, read all values and do all calculations using double.

Sample Runs:

Enter initial amount, annual interest rate and number of months: 100.0 12.0 1
After 1 months you will have $200.00

Enter initial amount, annual interest rate and number of months: 25.5 0.04 360
After 360 months you will have $17,757.25

Note only modification is output has two decimal point precision, its currency; Once again use
String.format or System.out.printf to output number with only two decimal points. Info on format specifiers.



  • Submit Filename: (Ninth Edition Page 78)
  • Review Chapter 4 and re-take Chapter 4-5 Canvas Quiz

submit (9th. p 221; 10th p243 6.36) (Methods)

submit Filename: (Ninth Edition Page 221; 10th Edition p 243 6.36)

( Geometry: area of a regular polygon) A regular polygon is an n- sided polygon in which all sides are of the same length and all angles have the same degree ( i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is

Area = (n * s^2) / (4 x tangent( PI/n ) );

Write a method that returns the area of a regular polygon using the following header:

public static double area( int n, double side)

Write a main method that prompts the user to enter the number of sides and the side of a regular polygon and displays its area. Here is a sample run:

Enter the number of sides: 5
Enter the side: 6.5
The area of the polygon is 72.69

Sample Run 2:

Enter the number of sides: 10
Enter the side: 100
The area of the polygon is 76,942.09

Once again we will be printing the calculated output with %,.2f (Percent comma dot 2 f)


  • Submit Filename:
  • Take Chapter 4-6 Canvas Quiz a third time.


submit (10th page 282 7.26) (1D Arrays)

Submit Filename: (Ninth Edition Page 260; 10th Edition page 282 7.26))

"( Strictly identical arrays) The arrays list1 and list2 are strictly identical if their corresponding elements are equal. Write a method that returns true if list1 and list2 are strictly identical, using the following header:

public static boolean equals( int[] list1, int[] list2)

Write a test program that prompts the user to enter two lists of integers and dis-plays whether the two are strictly identical. Here are the sample runs. Note that the first number in the input indicates the number of the elements in the list." page 260

Sample Run...

Enter list1: 5 2 5 6 1 6
Enter list2: 5 2 5 6 1 6
Two lists are strictly identical

Sample Run...

Enter list1: 3 4 5 7
Enter list2: 3 4 5 6
Two lists are not strictly identical

Both prompts are not newline terminated, the final line is newline terminated.

NetBeans Sample Run With...
String data = "5 1 2 3 4 5\n" + "6 1 2 3 4 5 6\n";

Scanner in = new Scanner( data ); //make sure you use for stream on input

Enter list1: Enter list2: Two lists are not strictly identical
BUILD SUCCESSFUL (total time: 1 second)

NetBeans Sample Run:
Enter list1: 3 1 2 3
Enter list2: 0
Two lists are not strictly identical
BUILD SUCCESSFUL (total time: 7 seconds)
NetBeans Sample Run: run:
Enter list1: 0
Enter list2: 2 1 1
Two lists are not strictly identical
BUILD SUCCESSFUL (total time: 7 seconds)


  • Submit Filename:
  • Review Chapter 7 and take Chapter 7 Canvas Quiz



submit (10th 7.11 page 278)

Submit Filename: - (9th Edition p 247; 10th Edition p 278 Exercise 7.11)
Watch a Canvas chapter 6 Web-cast

Programming Exercise 6-11M page 223 (9th Edition 6.11 page 257) computing deviation, hints....

  • test your program using the book's sample array data,
  • but for submit read in 10 doubles
  • declare all variables as double

Sample Input 1: 1.0 3.0 5.5 7.6 22.0 10.0 7.0 8.0 9.0 3.23
Output (No input prompt)...

The mean is 7.63
The standard deviation is 5.81

Sample Input 2: 23.0 45.5 34.6   45.7  56.7
89.0 78.0 89.654 78.34 100.34
The mean is 64.08
The standard deviation is 26.42

For standard deviation use the corrected sample standard deviation
- std = √ { 1/(N-1 ) ∑ (xi - xavg)2 }

Sample Standard Deviation Formula | How to Calculate?


  • Will be using the standard output format System.
  • System.out.printf( "The mean is %,.2f\n", mean(x) );
  • System.out.printf("The standard deviation is %,.2f\n", deviation(x) );
  • Standard deviation discussion.


  • Complete Canvas review quiz chapters 1-5


submit revised Descending Order

Submit Filename: (9th Edition page 259 6.20; 10th Edition Page 280 7.20)
Watch a Canvas chapter 6 Web-cast

You first read in an integer representing the size of the double array (e.g., n=3), you then read in n doubles (e.g., -23.45 587.5 45.0). You output the descending sorted array each value has a space separator, except the last number which will be new line terminated. You are using selectionSort to sort the array.

Sample Input 1: 15 1.0 3.0 5.5 7.6 22.0 13.0 7.0 8.0 9.0 3.23 32.0 9.0 19.0 8.0 7.6
Output (no input prompt): 32.0 22.0 19.0 13.0 9.0 9.0 8.0 8.0 7.6 7.6 7.0 5.5 3.23 3.0 1.0

Sample Input 2: 3 -23.45 587.5 45.0
Output: 587.50 45.0 -23.45
Note Output String is "587.50 45.0 -23.45\n"


  • test your program by hard coding an array of doubles, (e.g., double[] list = { -23.45, 587.5, 45.0 }; )
  • for submit you will first read in the size of the array, and then that number of doubles all from standard input (
  • Declare all variables as double, output all numbers using just System.out.print not System.out.println.
  • You will output the numbers sorted in descending order space delimited, with last number ending with only a newline.
    All numbers will end with a space, except for the last one which ends with a newline.


  • Declare input array with no size (set size after reading in size). double[] list;
  • Create a Scanner( ) object, then read in the array size, (int size = in.nextInt());
  • Use the array size to set the size of your list list = new double[ size ];
  • Then read in doubles using nextDouble(), do this from i=0; i<size
    for( i=0; i < list.length ; ++i ) list[ i ] = input.nextDouble( );


submit Exercise7_26M ( 10th page 314 8.26 ) (Multidimensional Array)

Submit Filename: (9th edition page 290n 7.26; 10th page 314 8.26)

( Row sorting) Implement the following method to sort the rows in a two-dimensional array. A new array is returned and the original array is intact.

public static double[][] sortRows( double[][] m)

Write a test program that prompts the user to enter a matrix size and then matrix contents row then column. Output a display of the row sorted matrix. Here is a sample run:

Enter matrix size: 2
Enter a 2 by 2 matrix row by row: 2.0 3.0 5.0 4.0
The row-sort matrix is...
        2.00    3.00
        4.00    5.00 
Here is a second sample run:
Enter matrix size: 4
Enter a 4 by 4 matrix row by row: 90.99 17.82   85.38   50.46
16.50   52.15   44.18   3.24
82.37   66.76   43.81   91.94
39.49   66.47   87.47   90.16
The row-sort matrix is...
        17.82   50.46   85.38   90.99
        3.24    16.50   44.18   52.15
        43.81   66.76   82.37   91.94
        39.49   66.47   87.47   90.16

Sample Run 3:
We will be reading from a String instead of the local modified code is... String data = "3 2 3 4\n5 6 7\n8.0 9.5 10.3\n"; Scanner in = new Scanner( data ); Nota Bene, make sure you set the Scanner back to for submit. Program Output Using above data string... Enter matrix size: Enter a 3 by 3 matrix row by row: The row-sort matrix is... 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.50 10.30 Sample Run 4 (Only input is 0 - nota bene, on this case it could also be 0 2 3 4 5 doesn't matter) Enter matrix size: 0
Enter a 0 by 0 matrix row by row: The row-sort matrix is...

Output notes each number on output will begin with a tab, we have tab delimited fields. Last number will terminated with a new line. We will output all double precision numbers using the same format "\t%,.2f".


  • You need to read in matrix size and then use it to create the matrix object.
  • If you have the matrix double[][] x = new double[3][]; //creates space for three rows of pointers but not for content
  • x[0] = new double[3]; //creates space for three elements of first row;
  • You should create a createMatrix( int size ) and also a printMatrix( double[][] m ) method
  • on createMatrix( int size, Scanner in) or make the Scanner object global.
  • To make a global Scanner object before the main method use public static Scanner in = new Scanner( );
    Nota Bene, you can only create a Scanner object tied to once. When you create a Scanner object, it creates a memory buffer. The buffer holds data before it is read (i.e., in.nextDouble() ). So if you create a Scanner object in the main method the memory buffer will store both the size and matrix double data. If you try to create a new Scanner object in the method createMatrix, createMatrix will have an empty memory buffer.


  • Remember double[][] x = new double[3][3]; ICreates 3 1D arrays x[0], x[1], and x[2]
  • You can use java.util.Arrays.sort, to sort each row, it is just Arrays.sort( x[0] );
  • make sure you use one Scanner object for all methods


  • You have completed the review, hopefully you have not used up more than 3 weeks to do this.


submit Exercise8_1 & Exercise8_12M (Strings)

Submit Filename: (8th Edition 9.1 page 335; 9th Edition 9.1 page 362; 10th Edition Page 155 4.21)
Submit Filename: (8th Edition 9.12 page 337; 9th Edition 9.12 page 364; not in 10th edition; Anagrams are just two words which have the same letters)

Programming Exercise 8_1(checking SSN) and 8_12M (One word Anagrams)

Exercise 8-1 page 155 10th Edition: "(Check SSN) Write a program that reads a word from standard input and checks if it is a legal Social Security number in the format DDD-DD-DDDD, where D is a digit. Your program should check whether the input is valid."

can be solved easily using a regular expression. Hint what do these two match "\\d\\d$" or "[0-9]{2}+$"

Sample Run 1 (user enters 232-99-5435)

232-99-5435 valid SSN

Sample Run 2 ( user enters 123-4-5678 )
123-4-5678 invalid SSN

NetBeans Sample Run: (User enters 123-22-1234) 
valid SSN
BUILD SUCCESSFUL (total time: 10 seconds)

NetBeans Sample Run: (User enters 123-345-234) 
invalid SSN
BUILD SUCCESSFUL (total time: 12 seconds Modified, read in two words, output they are an anagram or are not an anagram

Sample Run (User enters evil and veil)

evil  veil  
evil and veil are an anagram 

Sample Run 2 ( User enters EvIL and VeIL ) 
 EvIl VeIL  
 EvIl and VeIL are an anagram    
Sample Run 3 ( user enters ate eaten)  
 ate eaten
 ate and eaten are not an anagram  

submit Exercise9_1 Class Time convert Milliseconds to Hour, Minutes, Seconds drop days

The filename and input class (with public static void main) should be the exercise name. For example you can have the class Exercise9_1 with a public static void main which creates your Time class. The Time class is a friendly class, no access modifier before the class name. So you have two classes in public class Exercise9_1 and class Time.

Submit Filename: (8th Edition page 366; 9th Edition page 399 10_1; 10th Edition Page 399 10.1)

Programming Exercise 9_1

Make sure you declare all Time variables as long

public class Exercise9_1 {

public static void main( String[] args )
{ Time t = new Time( );

class Time { //class Time has not access modifier it defaults to friendly

//you could just save long timeMilliseconds and use equations in gets to generate hour, minute and seconds
private long hour; //we are not print out days, only the hours for the current day
private long minute;
private long second;

... }

You will be inputting a Long Millisecond into the constructor, program should use the prompt "Enter milliseconds: ", you output the number of Hours Minutes Seconds. Drop off any extra milliseconds and all full days.

Sample Run ( user enters 100013)

Enter milliseconds: 100013
0 1 40

Sample Run 2 (user enters 606,000 )

Enter milliseconds: 606000
0 10 6

Sample Run 3 (user enters 6543431643)

Enter milliseconds: 6543431643
17 37 11

Nota Bene, for assignments with multiple classes, The filename and input class (with public static void main) should be the exercise name. For example you can have the class Exercise9_1 with a public static void main which creates your Time class. The Time class is a friendly class, no accessors before the class name and in the same file as, also make sure you delete any package declarations.

Do not output, the word output, Java scanner allows commas in integers. Hours have a value from 0..23; You will not be printing out days.

submit friendly class Rectangles

Submit Filename: (8th Edition page 370; 9th Edition page 405 10_13; 10th Edition Page 404) 10.13)

This assignment requires you to write some advance code, the Canvas webcasts talks about how we solve complex problems. Assignment also viewgraph intro, an assignment API and jUnit Test Data, Canvas webcast covers jUnit testData and assignment.

Exercise Input...

  • You will read a line of data with either 1, 3 or 4 doubles numbers.
  • Numbers will be separate with a space, last number terminates with a newline
  • When you read in a line with only number it will have a -1, once you read this line - print a newline and terminate your program
  • If you have 3 doubles on the line the values represent a square with x, y and radius
    • x,y is center of the square, x and y can be negative
    • Radius is the distance from the center to the four sides.
    • The height and width are twice the radius.
    • Note a square is a rectangle with all four sides the same size.
  • If you have 4 doubles the values represent x, y, width, height
    • x,y are the center of the rectangle, they can have negative values;
  • radius, width and height are always positive; x and y centers can be negative.
  • This assignment has an API of an already written solution.

Output consists of 4 lines...

  • perimeter: doubleValue with 3 digits right of decimal point
  • area: doubleValue with 3 digits right of decimal point
  • then read in another rectangle 3 or 4 doubles, if you have the first rectangle you will always have the second rectangle
    if you have two rectangles then compare rect1 to rect2, if you have a third rect then compare third to fourth rectangle.
  • contains: true or false (true if second rectangle is contained with first rectangle, otherwise false )
  • corner points inside:: 0..4 (count each corner point of rect 2 that is inside of rect 1; for contains this value is 4)

Sample Run: (user enters 4.0 5 2 then 1.0 1 3 1 then -1;
String data = "4.0 5 2\n1.0 1 3 1\n -1\n " - see assignment API and jUnit Test Data, video on Canvas covers assignment

Enter first rectangle: width: 4.00 height: 4.00
area: 16.00 perimeter: 16.00
Enter second rectangle: contains: false
corner points inside: false

Enter first rectangle:
BUILD SUCCESSFUL (total time: 0 seconds)

Sample Run 2:

Enter first rectangle: 5 6 7
width: 14.00 height: 14.00
area: 196.00 perimeter: 56.00
Enter second rectangle: 6 6 6
contains: true
corner points inside: true

Enter first rectangle: 2 3 4 5
width: 4.00 height: 5.00
area: 20.00 perimeter: 18.00
Enter second rectangle: 2 3 2 1
contains: true
corner points inside: true

Enter first rectangle: -2 -2 4 1
width: 4.00 height: 1.00
area: 4.00 perimeter: 10.00
Enter second rectangle: 1 1 1
contains: false
corner points inside: false

Enter first rectangle: -2 -2 2
width: 4.00 height: 4.00
area: 16.00 perimeter: 16.00
Enter second rectangle: 1 1 1
contains: false
corner points inside: true

Enter first rectangle: -1
BUILD SUCCESSFUL (total time: 0 seconds)


  • You may want to include a Rectangle friendly class with constructors using 3 or 4 arguments.
  • Read a line using nextLine, then use String.split( "\\s+" ) to determine how many tokens you have 1, 3, or 4
  • for output we are using our standard 2 digits past decimal point with a comma every three digits before decimal point
  • Note for Enter rectangle: we have the standard colon space, but then we output a newline.
  • For the overlaps and contains, you need to break it down into logical steps ..
    • First write a method given a lower left and corner and height and width of a rectangle, return true if a points falls within the rectangle.
      For example rectangle lower left corner is 0,0 height and width are 2; the point 1,1 and 1,2, are inside, the point 1, 2.2 is outside.
    • If all four points fall within you have a contain, if only 1 you have an overlap
  • You may want to think about this before going to bed.
  • You may also want to refer my API on this assignment, on how to separate a difficult task, into manageable components.

Exercise9_12 is a little harder than most of the previous assignments, you need to move from solving problems using a sequential brute force, into OOP. With OOP we break up a problem into Classes, each class has methods and properties. Each method accomplishes a single task. You may want to refer to this API, but in general never violate these guidelines....

  • Never perform the same task twice, you should be creating a method and calling it twice.
  • If else should never be more than 3 levels deep.
  • Avoid too many variables, if something is used once or easily calculated it should not be a separate variable. Rectangle should have only 4 global variables. (x,y,width, height).
  • More than 30 lines of sequentialize code.

If you violate any of the above guidelines, then you are not breaking your code down into the proper number of classes and corresponding methods.

After analyzing the API, and thinking about this problem, it should be evident that the key method for solving this is boolean contains( double x, double y).

submit Exercise10_2M (Inheritance and Polymorphism)

Submit Filename: (8th Edition page 403; 9th Edition page 442 11_2; 10 th Edition page 445 11.2)
Based on API - You have a jUnit test Data, refer to 11/20/2018 on how to implement jUnit testData.

Main class and filename will contain the friendly classes: Person, Student, Employee, Faculty, and Staff. Your main function will read an input word (aka record) which terminates in ";" semicolon. A record of data is a collection of data fields.

For example each Person input record has the following fields::
"Person#Mickey Mouse#1000;"

Note each record ends with a ;, we use # as the field delimiters. # and ; are respectively the reserved field and record keyword separators. First argument for each record will the class name Person, Student, Employee, Faculty, Staff or Exit. On exit you will exit. You need to create a friendly class for Person, Student, Employee, Faculty and Staff. After the class name you then read in the arguments to construct each class. You classes will have the following properties (which parallel the input fields)...

  • Class Person has person: String name, String address String phoneNumber and String emailAddress.
  • Class Student extends Person has properties: classStatus: freshmen, sophmore, sophmore+, junior or senior Type can be String or enum type.
  • Class Employee extends Person has properties: String office, double salary and long dateHired.
  • Class Faculty extends Employee has properties: long[] officeHours, rank either adjunct, assistantProfessor or Professor.
    all dates i.e., dateHired and officeHours are milliseconds since Unix epoch. all dates are printed using class Date.toString()
  • Class Staff extends Employee has properties: String title;

Input is in same order as listed above in the class property descriptions, all classes have fixed number of inputs except faculty which may have multiple office hours.

Write a toString for each class, the toString method will print class name then a tab(\t), each property name followed by a colon, a space and the then value, each property name pair is separated by tab key (\t) each toString methods terminates with a new line. Inherited classes should call underlying toString methods stopping at class Person. Office Hours print out property name officeHours: each office hour separated by comma. For example, the base class person has the output string...


toString for Staff will look like

return "Staff\ttitle: "+ title + "\n\t" + super.toString(); //print out titile then call super class Person.

Sample Run 1 (first 4 lines are input; note Faculty will always have Employee then Person data)
Person#Joe Gaucho#28000 Marguerite;Faculty#1234153524#1341244#1234150000#Adjunct;Employee#bgs210#20000#123455000;Person#Mickey Mouse#Disneyland#800;

Person      name: Joe Gaucho        address: 28000 Marguerite Parkway      phoneNumber: 949-582-4800        emailAddress:
Faculty officeHours: Wed Jan 14 22:49:13 PST 1970, Wed Dec 31 16:22:21 PST 1969, Wed Jan 14 22:49:10 PST 1970   rank: Adjunct  
	Employee        office: bgs210  salary: 20000.0 dateHired: Fri Jan 02 02:17:35 PST 1970
	Person  name: Mickey Mouse      address: Disneyland     phoneNumber: 800 1DisneyemailAddress:  

Sample Run 2 (User enters Person#Wiley Coyote#2800 Palm; on next line Exit#)

Person#Wiley Coyote#2800 Palm;

Person  name: Wiley Coyote      address: 2800 Palm Spring       phoneNumber: 800-777-1234       emailAddress:  Exit# 
Sample Run 3 (Whenever input has a Student, you will always have Person data next, you need to read the person data and pass it to the Student constructor)
Input: Student#junior;Person#Jane Smith#1000 Santa;Exit#; Student classStatus: junior
Person name: Jane Smith address: 1000 Santa Lane phoneNumber: 1-800-234-4567 emailAddress:

Nota Bene
Lines above are automatically word wrapped, but your input data is not newline terminated. The terminators are ; and #. You don't have to worry about missing or incorrect data.

You should write a Scanner that reads the next word, using the delimiter ; semicolon. Once you read this word split it up tokens (fields/properties) using the delimiter # pound sign.

When your first word aka token is an...

  • Exit, exit the program
  • Person, call the Person constructor with the rest of the words/tokens
  • Student, read the next word up to ; semicolon. Then call the student constructor with class status, and the Person words/tokens. For example your student constructor is...
    public Student( String status, String[] personData ) { super( personData ); //call Person Constructor
    In the above Student constructor, immediately calls the Person constructor. Both Person and Student should have a toString method which meets the above output specifications.
    the class would be System.out.println( new Student( data, "#" ) );

submit Exercise11_1M (Abstract Classes and Interfaces)

Submit Filename: (8th Edition 14.1 page 492; 9th Edition 15.7 page 593; 10th Edition Page 530 13.5)

Modify the GeometricObject abstract base class (Listing 11.1 and 14.1 8th edition),...

  • implement the java.lang.Comparable interface. The compareTo method should be in the GeometricObject and compare two areas returning an int after subtracting.
  • Add a protected constructor that will accept color, filled and dateCreatedInMilliseconds. You should set the default no argument GeometricObject constructor to private.
  • also implement the java.util.Comparator interface. Two geometric objects are equal if both area and perimeters match. Equals method returns true or false. The compare method should return the same value as compareTo. In most situations you only implement the Comparable interface, the compareTo method is used by several Java class, (e.g., java.util.Arrays.sort). The equals method in Comparator is already defined in java.lang.Object. So in most situation we implement Comparable, and write the equals method to override java.lang.Object.equals. However, in this case implement both.

Define two subclasses for GeometricObject, Circle and Rectangle. The compareTo, compare and equals method should be able to compare 2 circles, 2 rectangles or a circle and a rectangle.

Circle will have 4 arguments on one line

radius color fillTrueorFalse dateCreatedMillisecondsSinceUnixEpoch

Rectangle will have 5 arguments on one line

width height color fillTrueorFalse dateCreatedMillisecondsSinceUnixEpoch

Your will read in two lines, number of arguments determine circle or rectangle.

For example...


2 blue false 223455666000
3 3 black true 23344456566000


Circle Created on Sat Jan 29 23:01:06 PST 1977
color: blue and filled: false area: 12.57 perimeter: 12.57
Rectangle Created on Mon Oct 04 04:16:06 PDT 2709
color: black and filled: true area: 9.00 perimeter: 12.00
Object1 compareTo Object2 is 3
Object1 equals Object2: false

Have Two hard coded input strings
String data = "4.5 4 blue false 99999991543543\n5.1 orange true 94343936598965\n"; Output is... Rectangle Created on Tue Nov 15 23:25:43 PST 5138 color: blue and filled: false area: 18.00 perimeter: 17.00 Circle Created on Wed Aug 22 10:03:18 PDT 4959 color: orange and filled: true area: 81.71 perimeter: 32.04 Object1 compareTo Object2 is -63 Object1 equals Object2: false

Nota bene - Use Polymorphism

Nota Bene again, using standard %.2f for outputting area and perimeter

The data types for both object 1 and object 2 are GeometricObject, You count the number of arguments to determine which constructor to call either Circle or Rectangle.


To have 4 classes in one file, you need to set three of the class to friendly, Friendly is the default access modifier. For Example,

public class Exercise11_1M { //must match file name aka Assignment name
class abstract GeometricObject implements Comparable ...
class Rectangle extends GeometricObject { //note no access modifier

Hints for Submit

Hints for submit, you need to submit one Exercise11_1M
with 4 classes:

public class Exercise11_1M

and three friendly classes in the same file

abstract class GeometricObject implements Comparable<GeometricObject>
class Circle extends GeometricObject
class Rectangle extends GeometricObject

drop all access modifiers they are all friendly except for class Exercise11_1Myou will need to submit

public class Exercise11_1M

and three friendly classes in the same file

abstract class GeometricObject implements Comparable<GeometricObject>
class Circle extends GeometricObject
class Rectangle extends GeometricObject

drop all access modifiers they are all friendly except for class Exercise11_1M

submit Exercise18_1M (Exceptions) - Extra Credit

Submit Filename: (8th Edition 13.1 page 620; 9th Edition 14.1 page 554; 10th Edition page 488 12.1)

Assignment is part of class API and has jUnit test data, canvas 12/4/2018 Webcast provides test code, and writes part of the program.

You will be reading a line of data either...

  • number operator number
  • -1

Read in all numbers as double, and when input has correct syntax output a double. You will never have more than 3 arguments per line. We are reading lines in this assignments. Arguments on line are standard free-form format white space delimited, new line terminated.

Your Calculator methods needs to handle five Exceptions:

  1. first throw EOFException when you read a line with only -1, then terminate program.
  2. second throw new NoSuchElementException( "Have only x arguments need 3" ); when you have less than three argurments per line. Make sure you trim data.
  3. third output NumberFormatException, if first arugment is not a number. Just output the standard Double.parseDouble exception message.
  4. fouth Legal operators are: +,-,* and /. If you need get a legal operator . You need to throw an IllegalArgumentException, you will be using the constructor IllegalArgumentException( "Legal operators are +,-,* and /. You entered: " + BadArgument ).
  5. fifth output NumberFormatException, if third argument is not a number

If no exceptions occur you echo the input line and replace the newline with =result\n. Using our standard %,.2f for result.

For each legal line read print out a line with the result of the operation. For example...

Sample Run 1 Scanner in = new Scanner( "4 + 5\n 2 - 3\n-2 - -3\n2 * 3.0\n2 * 3\n2 * 0\n5.0 / 2.0\n" );
4 + 5=9.00
2 - 3=-1.00
-2 - -3=1.00
2 * 3.0=6.00
2 * 3=6.00
2 * 0=0.00
5.0 / 2.0=2.50
BUILD SUCCESSFUL (total time: 0 seconds) Sample Run 2 Scanner in = new Scanner("4 + 5\n4 - 5\n2/3\n4 x 2x\n\n4 * 3ab\n-1\n"); run:
4 + 5=9.00
4 - 5=-1.00
java.util.NoSuchElementException: Have only 1 arguments need 3
java.util.InputMismatchException: Legal operators are +,-,* and /. You entered: x
java.util.NoSuchElementException: Have only 1 arguments need 3
java.lang.NumberFormatException: For input string: "3ab"
BUILD SUCCESSFUL (total time: 0 seconds) Hints Scanner in = new Scanner( ); // "2.0 3.0\n 5.5 6.5\n 23.4\n a 23\n2 2\n" while( in.hasNextLine( ) ) { try { String s = in.nextLine( ); String[] args = s.split( "\\s" ); //split by whitespace double d1 = Double.parseDouble( args[0] ); if( args.length < 2 ) throw new NoSuchElementException( "Have only " + args.length + " arguments need 3" ); double d2 = Double.parseDouble( args[1] ); System.out.println( s + " sum is " + (d1+d2) ); } catch( NoSuchElementException e ) { System.out.prinltn( e.getClass().getCanonicalName() + e.getMessage(); ) } catch( NumberFormatException ) { System.out.println( "Need a number not " + s ); } }//end while

submit ClientSocket.javaExtra Credit due email me if you want to this assignment

Thread - Socket Assignment Client Socket Reads Integers Sends it to Server Socket, Client Prints Out Response.

Watch or Attend the 12/11 Webcasts - Sample code.

submit (submit not available yet for this assignment, but write your server/client first)

Create a Client Socket that reads a integer number from standard input, stops reading from stdin on EOF or if it reads a -1; On EOF or if it reads a -1, a -1 is sent the serverSocket which terminates the connection. On non EOF client sends the number to a serverSocket at localhost port 2000, the Server program should be thread based and start a new thread for each new client. The server program will return an integer number. Your client socket program, should output the number returned from the server socket newline terminated. For local testing you need to create both the server and client socket program. On cim you will only be submitting the program, I already have a server socket program running on cim using port 2000.

We will be using DataInputStream.readInt and DataOutputStream.writeInt, to process all socket I/O.