HW8 Recursion Homework

Due: Monday, Nov. 18, 11:59pm

Following is worth 10 out of 10 points.

Go to https://codingbat.com/java/Recursion-1

Choose 2 problems out of the group to code. (No factorial, No fibonacci, No sumDigits, No powerN, No problems we did in class.)

Use the template so I can enter vales to test your code. Two separate programs are fine. Submit all in one gist.

Following Problem is worth 12 out of 10 points.

Problem inspired by this article: https://medium.freecodecamp.org/how-to-impress-interviewers-by-using-recursion-in-javascript-with-es6-features-a14c763110d7

Using recursive techniques only!

Write a function that takes as input a String and returns a “report” on the frequency of characters in the String.

ie input: “bbbdaacccced”

output: [{‘b’, 3}, {d, 2}, {c, 4}, {a, 2}, {e, 1}]

The “report” needs to be an ArrayList and each element of the ArrayList is a class that wraps a character and its count.  Much like a “BabyName”?

Do not give me a solution that doesn’t involve an ArrayList.

Of course, use the template.


HW8 Computing Standard Deviation

Due: Friday, November 15 11:59pm

Problem 7.11 (Computing Deviation) page 278.  Write your program to read a data file. You’ll prompt for a filename and use that name to open and read a data file.  You may either read the data off your machine’s hard drive as a file, or read it from a website.  Assume the data file has an integer as its first number that indicates the number of data points that follow in the file.  Here is some sample code to read the data: Sample Data File Reading Code

Make sure you use the Application Template so you can process multiple data files.  Code as many methods as you can that make sense to create this application.

Here are 3 different data files.  Download and copy them into your project folder.   They are also located on my website:  https://cs.stcc.edu/~silvestri/csc111/

These data files were generated from a website: https://random.org/

problem7-11

 

HW7 Calculate sin(x) or cos(x) using loops and methods with Solution

Retake Due: Wednesday, Nov. 6 10:00am

Do the cosine series as opposed to the sine. Same requirements as the original sine assignment.

Due: Friday, Nov. 1, 2019 11:59pm

Solution

Write an application that uses the template that calculates the sin(x).  The sin(x) can be calculated using the following series:

A program consisting of only a main method will not get you a passing grade.  You must break up your logic into as many methods as necessary to solve this problem.  The more methods, the better the grade.

At the very minimum, for each run of the logic, you will prompt the user for x (in degrees).  Remember, the series requires x to be in radians.  (Use Math.PI / 180 as your conversion factor.)  You will also prompt the user for the number of terms to calculate in the series.  You’ll output your series calculation, as well as Math.sin(x), and the difference between the two values to see how close your calculation is.

At the end of your logic, you’ll ask the user if they want to repeat the calculations.

Your grade will be based on the following criteria:

  • how much of the application is finished
  • whether it works
  • if you coded methods
  • the number of methods
  • if you formatted the output values using the printf method (assume just 6 decimal places for the output display)

HW7 Names Application with Solution

Solution

Phase 1 – Building the Name class – Due: Friday, Oct 25 11:59pm for MWF section; Saturday, November 2 11:59pm for TTh section

Phase 2 – The Completed App – Due: Wednesday, Oct 30, 11:59pm for MWF section;
Saturday, November 2 11:59pm for TTh section.

This assignment is just way too cool.  It exercises many of the topics we discussed his semester; not to mention, it is also a useful utility.  Start coding now!  This is not the type and homework you can finish two hours before the deadline.

Warning! Do not create a GUI if the basic operation of the classes described below hasn’t been properly developed.  Don’t waste time on a GUI that doesn’t work.  You will not get extra credit for a dysfunctional GUI.  If you code the classes properly, and they work in a command line app, then you should be able to plug and play these classes in a GUI that calls their public methods.  That will give you extra credit.

The following database of Names (Zip) is maintained by the federal government and is located here:

https://www.ssa.gov/OACT/babynames/limits.html

It contains text files of names from 1880 to 2018.  Each file is a CSV file capable of being imported into any popular spread sheet.

You may access these files online from my website located here:

https://cs.stcc.edu/~silvestri/names/

Each line of the text file contains the following info:

name,sex,number

where name is the name, their sex (M/F), and the number born with that name.

Since this is a comma separated value (CSV) file, use the following sample program to read a data file:

https://gist.github.com/bytecodeman/ef4e0d2ab9a9beab177ee6426eb213ec

Your application will use our application template to prompt for start and ending years, as well as an integer representing the top number of names to display.  The app will read data from those years and display the top number of names of name, sex, and the total number of babies born with that name in the specified range. 

Error check these inputs.  Year input allow for only integers and must be positive.  The start year must be ≤ to the end year.  Years input must map to a datafile.  For example, you can’t enter a 1879 year as there is no such file.  You can’t enter 2019 or 2020 as that year hasn’t happened or finished yet.  Common sense on the inputs!

For instance, you enter 2010, 2015, 3.  What the app displays is (Data is totally contrived!):

Males:

  1. Tony, 23456
  2. Bob, 22123
  3. John, 20123

Females:

  1. Mary, 23453
  2. Joan, 21345
  3. Amelia, 19456

The heart of this application is one ArrayList! 

Name class Specifications (Phase 1 of Project)

You will create a class called Name that contains the instance variables, name, sex, and number. The class will have just 1 constructor that takes 3 parameters to initialize the instance variables.

You should provide getter and setter methods for each instance variable.  Error check the setters.  (i.e sex should only be “M” or “F”, name can’t be empty, number can’t be negative, etc.)

This class must also contain the following methods:

equals – Create a standard equals method.  Use the name and sex fields to check for equality. It is this equals method that the ArrayList uses to determine if a name is already in the list. Remember NO duplicates!  If a name is already in the list, you will simply access the Name object for that name and add to the number the number of additional people with that name.

compareTo – The Name class must implement the Comparable<Name> Interface.  It is the comparable interface method compareTo that you will use to sort the ArrayLists in descending order.  Look at the number field in the Name.  Base your logic on that.

toString – You know every class that you intend to print out needs one.  Make sure you output the name and number for the name.

A solution to this class will be provided after the due time so you can proceed with the Phase 2 App completion.

NameStats Class Specifications

Maintain 1 ArrayList of Name.  Have the constructor null out these fields.

A public Constructor that takes 3 int values:

  • Start Year
  • End Year
  • Number of Top Names desired.

and saves these values as fields.  Error checking these values would be appropriate.  If bad values were passed, throw an exception.

A method (ok to make it public) that creates and builds the Arraylist.  This list could potentially have 10,000+ names.  Use Collections.sort to sort the ArrayList by the number people who have a particular name.  If your names are appearing in ascending order, small numbers first, then you can use the Collections.reverse method to rearrange the list.

Hints on this method:

Don’t use ArrayList contains method to determine the existence of a name in the list.  It just returns a boolean.  Use the indexOf method.  It returns an index of where the name in the list or -1 if it isn’t in the list.

Also understand that the get method of ArrayList returns the reference of the name not a copy.  So you can update the number immediately (through getters and setters) in place.

Some public methods:

A public method called getTopMaleNames() that returns an ArrayList of males that is as large as “Number of Top Names desired”.

Another public method called getTopFemaleNames() that returns an ArrayList of females that is as larges as “Number of Top Names desired”.

Last Day to Withdraw from a Course is Monday, November 25

Last Day to Withdraw from a Course is
Monday, November 25

Withdrawal Form

If you haven’t been keeping up with the work, have a low grade average, or have missed a multitude of classes, please drop the class. I will issue a failing grade if your average is below a 60.

If the course has an associated lab, please drop that as well.

There is no extra work and no last minute scaling of grades.

Unless you have a medical issue that can be verified by the school, there are no extensions, extra work, or any other way for you to extend this semester.

Use the TEMPLATE!!!

A few things apparently need to be explicitly stated as far as homework is concerned.

In case things are not mentioned in the homework, the following criteria ALWAYS apply:

  • Code must use the template.
  • Code needs to be written using the JDK 8 or better.
  • Code needs to contain the global header information mentioned in the syllabus.  All source code files must have the global header.
  • Code must be formatted properly using Eclipse’s formatting capabilities.
  • Code must use methods and classes to separate the logic.
  • Always email me gists of your source code.

JDK 10 USB Portable Environment

  • Download this 612MB zip file
  • Unzip the contents onto a freshly formatted USB drive.
  • Make sure the root of the USB has these 3 directories: eclipse, Java, workspace, and 1 file called js.cmd.
  • When you want to start coding in this environment, click the js.cmd file. It will launch eclipse.
  • Projects get stored in the workspace directory.
  • Be sure to exit eclipse and wait for the shell window to close. Then eject the USB drive, or you will lose your work!

Why JDK 10? It’s the last version of the JDK that has JavaFX built in. JavaFX is a technology that allows building GUI code. We will use that technology in the CSC-112 Intermediate Java course.

That’s not to say the newer JDKs can’t compile JavaFX. It’s that JavaFX is a separate download and is a chore to incorporate in the JDK. I will work on doing that over the semester break and provide an updated JDK Portable Environment.

CSC-111 In Class Looping Exercise

Due: 12:00pm today

Write code that keeps prompting for a positive number. When it gets that positive number, it keeps track of the largest positive number it finds.

If a negative number is entered, quit the process and print out the largest positive number.

Copy and Paste this code to get you started:

// Put your name here

import java.util.Scanner;

public class FindMaximumValue {

 public static void main(String[] args) {
     Scanner input = new Scanner(System.in); 
     System.out.print("Enter a positive number: ");
     int max = input.nextInt();     
     if (max < 0) {
        System.out.println("Can't Do this problem.");
        System.out.println("You can't follow directions.");
     }
     else {
         // Now write code that keeps prompting
         // for a positive number and keeps track
         // of the largest positive number it finds.


         // ...


     }
     input.close(); 
  }

}

HW5 Check SSN Problem with Solutions

Solutions: https://gist.github.com/bytecodeman/fe5ff16136c317e13120a1c91618a7dc

Due: Tuesday, Oct 15 11:59pm

checkssnSome additional requirements:

  • Enter the SSN as a String.
  • An SSN can have OPTIONAL HYPHENS!  But if they are there, they both need to be in their proper spots. So 123456789 and 123-45-6789 are both valid SSNs.
  • DO NOT USE LOOPS.  We haven’t studied them yet.  If you know loops, this problem will give you an appreciation for them.
  • Use the methods discussed in Chapter 4 as much as possible!
  • To avoid deep nesting of if statements, use a boolean variable and  expressions that look like:
boolean isValid = true;
isValid = isValid && character1 is a digit;
isValid = isValid && character2 is a digit;
. . .
  • Just to give yourself confidence in the expressions involving isValid, write the program assuming an SSN only has 2 digits.  Extending to 9 digits would be trivial.  Adding optional hypen logic would then be marginally harder.

Happy Coding!

CSC-111 In-class Exercise FizzBuzz with Solution

Alex Hartley’s Solution

Due in class only!!!

A classic interview question used by companies to see if a potential employee can really program is the FizzBuzz problem.

Enter a number. If the number is divisible by 3, output “Fizz”. If it is divisible by 5, output “Buzz”. If it is divisible by 3 and 5, output “FizzBuzz”. If the number doesn’t meet any of the divisibility rules, simply output the number.

Authenticate a User Code

Prompt for a Username and Password.

The credentials to check for proper access is:

Username: CSC-111
Password: JavaIsGood

Typically a username is checked with case insensitivity. Capital-A and lowercase-a are the same.  Passwords are always case sensitive.

If the user enters the proper info, they are allowed access to the system and you will print out: “Access Allowed”.

If not, print: “Credentials Not Correct.  Access Denied!!!”

https://pastebin.com/bKva1Jut

In class Chapter 3 Challenge

(Game: pick a card) Write a program that simulates picking a card from a deck of 52 cards. Your program should display the rank (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) and suit (Clubs, Diamonds, Hearts, Spades) of the card.

Here is a sample run of the program:

The card you picked is Jack of Hearts

Double Sum and Balance (Chapter 7 In class method challenge)

Solution: https://gist.github.com/bytecodeman/75c9c6be1ec2d85e1464cf75f1a889de

Find an element of an array such that the sum of all elements to the left is equal to the sum of all elements to the right. For instance, given the array [5, 6, 8, 11], 8 is between two subarrays that sum to 11. If your array is a single element, i.e. [1] , that element satisfies the rule as left and right sum to 0.

You will be given arrays of integers and must determine whether there is an element that meets this interesting criterion.

Function Description

Create a balancedSums function. It should return a string, either YES if there is an element meeting the criterion or NO otherwise.

balancedSums has the following parameter(s):

  • arr: an array of integers

Input Format

When using the template, in the process method, prompt for the size of the array. Then read in that many integers into an array. Pass that array to the balancedSums function and print out the result.

Output Format

For each test case print YES if there exists an element in the array, such that the sum of the elements on its left is equal to the sum of the elements on its right; otherwise print NO.

Sample Input

3
1 2 3

4
1 2 3 3

5
1 1 4 1 1

4
2 0 0 0

4
0 0 2 0  

Sample Output

NO

YES 

YES

YES

YES 

Rules for Homework!!!

A few things apparently need to be explicitly stated as far as homework is concerned.

In case things are not mentioned in the homework, the following criteria ALWAYS apply:

  • Code needs to be written using the JDK 8 or better.
  • Code needs to contain the global header information mentioned in the syllabus.  All source code files must have the global header.
  • Code must be formatted properly using Eclipse’s formatting capabilities.
  • Code must use methods and classes to separate the logic. (To be done soon)
  • Always email me gists of your source code.
  • No homework will be accepted after due date and time.  Submit your homework on time.

Exam #1 Friday, September 27

Let’s have our first exam covering chapters 1 and 2 on Friday, Sept. 27.  It will be an in class exam.

CLOSED BOOK/CLOSED NOTES.  COME EARLY TO CLASS AND BRING A PENCIL.

Go here for sample quizzes:

https://media.pearsoncmg.com/ph/esm/ecs_liang_ijp_11/cw/

Even though we didn’t go into too much detail in Chapter 1, that material is essentially Computer Concepts and is something you should already know.  If you don’t know it, study it!

CSC-220 Chapter 7 Searching and Sorting Examples

Sorting and Searching V1:
http://pastebin.com/Mrryf839

Sorting and Searching V2 using Arrays methods:
http://pastebin.com/Sk7e5GtX

Sorting Using BinarySearch routine (updated 9/17/18):
https://gist.github.com/bytecodeman/2375a479f829025dfe643b2c785a65fc

String Sorting:
http://pastebin.com/D57LPbB9

String Sorting V2 With Interfaces and Lambdas
https://pastebin.com/pV1sgRq8

Sherlock Holmes and the Beast (In class method challenge)

Solution: https://gist.github.com/bytecodeman/8e838d5f7c0e88af2f2b96c8aebf56ac

Sherlock Holmes suspects his archenemy Professor Moriarty is once again plotting something diabolical. Sherlock’s companion, Dr. Watson, suggests Moriarty may be responsible for MI6’s recent issues with their supercomputer, The Beast.

Shortly after resolving to investigate, Sherlock receives a note from
Moriarty boasting about infecting The Beast with a virus. He also
gives him a clue: an integer. Sherlock determines the key to removing
the virus is to find the largest Decent Number having that number of
digits.

A Decent Number has the following properties:

  1. Its digits can only be 3’s and/or 5’s.
  2. The number of 3’s it contains is divisible by 5.
  3. The number of 5’s it contains is divisible by 3.
  4. It is the largest such number for its length.

Moriarty’s virus shows a clock counting down to /The Beast/’s
destruction, and time is running out fast. Your task is to help Sherlock
find the key before The Beast is destroyed!

For example, the numbers 55533333 and 555555 are both decent numbers because there are 3 5’s and 5 3’s in the first, and 6 5’s in the second. They are the largest values for those length numbers that have proper divisibility of digit occurrences.

Function Description

Create a the decentNumber function in our class template. Function takes as input number of digits in decency. It should return a String of the numbers for the given length, or -1 if a decent number of that length cannot be formed.

In the template prompt for the number of digits in the decent Number, call the function, and output its result.

Sample Input

Input: 1
Output: -1

Input: 3
Output: 555

Input 5
Output: 33333

Input 11
Output: 55555533333

CSC-111 Homework 1

Due Friday, Sept 13  11:59pm.

Solution:

Solution to the Population Problem 1-11  or Solution to the Population Problem 1-11 With Variables

This problem is on page 31 in the textbook.

prob1-11

Do this problem without using variables, loops, or anything beyond what is discussed in Chapter 1. You’ll have a better appreciation for these advanced tools once you do the problem without them.

You need to submit a gist link to silvestri@stcc.edu of your code by the due date and time.

Download and Use JDK 10.0.2!!!

Link to: https://cs.stcc.edu/getting-familiar-with-linux-for-java-programmers/

Don’t use the latest Java 11. For whatever reason, Oracle decided to not bundle JavaFX with it.

If you really what to use Java 11, you’ll need to download and install JavaFX separately. I’ll leave you to google the instructions on how to do that.

Use JDK 10.0.2. It has JavaFX built in and is what is installed in our labs.

If you already installed Java 11, uninstall it entirely.  

Download JDK 10.0.2. Since Oracle is pushing the latest and greatest Java 11, you’ll need to jump through some hoops to get it. Here’s how:

  • Go to the JDK download page.
  • At the bottom of the page, there’s a Java Archive.  Click that.
  • Select Java SE 10
  • You may need to create an account to download it. Go ahead; it’s safe.

You’ll have a much better JavaFX experience!

Good Luck

Supplemental Instruction (SI)

Introducing Jimmy Alvarez, Java Certified Programmer. We are lucky to have his services as a Supplemental Instructor for all Java courses running this Fall 2019 semester.

The college has a new program called Supplemental Instruction (SI). Through this program, you will have the opportunity to meet weekly with our SI Leader, who will provide weekly review sessions for all interested students. The Leader is a current student who has recently taken the course and done well. They will be in class with you every day, hearing what you hear, and reading what you read. During each review session, you will have a chance to get together with your classmates to compare notes, discuss concepts that might be confusing, review material for tests and quizzes, and ask any questions that you might have.

Sessions will begin the week of September 8th, and run through the end of the semester. You can attend as many review sessions as you like; each one will be different because you will have new material to discuss. SI sessions are informal – bring any notes you have, your textbook, or a classmate! By coming to these sessions, you will be able to develop a better understanding of the course content as well as more effective ways of learning.

If you are unable to attend the group session, but would like to meet with the SI Leader, you can set up an individual time to meet with them. You can let them know you would like to make an appointment with them when you see them in class, or feel free to send them a note through their college email.

I am thrilled that we have this new opportunity for you, and I am hopeful that you take advantage of this program.

Sign up for a GitHub Account

If you going to be a programmer, then github is a site you’ll need to use.

Go here: https://github.com/ and create an account for yourself.  We will be using github for homework submissions.

In particular the part of github we’ll  be using is the gist function located here:

https://gist.github.com/

You can submit multi-file projects under just one URL! You also have a record of all your work in one convenient location.

Links and Resources for Java Courses

Liang 11th Edition Resources

Common Resources

Silvestri’s Special Apps Center!

Check out:   https://bytecodeman.com/specialapps/

I have some ideas for apps to add to this website, so please visit every now and then.

If you have an idea for an app that you think would be useful, would benefit a student, or would make the world a better place, please share ( silvestri@stcc.edu ), and if it isn’t too involved, and I have the time, I’ll code the problem and make it a special app.

Welcome to Professor Silvestri’s Math Courses

  • There are math lecture videos based on our textbook.  You can access them here:    Algebra Videos      (This is STCC’s portal website.  You’ll need to login with your Webadvisor credentials.) If you miss a class or need another prospective on the material, give these videos a try.
  • To take these courses, you must have access to a computer as this will be a hybrid lecture / online study course.  We will be using http://www.mymathlab.com/. So you must purchase the Student Access Code package and register using the appropriate Course Code (ID) shown above.
  • (Optional Textbook for Algebra)  Introductory Algebra through Applications, 3rd Edition, Akst and Bragg, 2012, Pearson Education, ISBN: 9780321746696algebratext
  • (Free Textbook)   Bedinelli Pre Algebra TextBook
  • (Free Textbook)  Bedinelli Algebra 1 Textbook
  • (Free Textbook)  Bedinelli Algebra 2 Textbook