Posts

Task 6a - Enums

Last Updated on: Nov. 17, 2020 6a.1 Define two enum, first for Gender and another for Month. Gender shall be enumeration of two values i.e. Male and Female. Month enum shall be defined with January, February, ... up to December as values. Month enum shall also store the number of days of each month. Define a User that shall be composed of id, name, gender and birthMonth attributes. Use above created enums for gender and birthMonth fields. Create a User object and initialize it from user input, gender shall be initialized in constructor and birthMonth shall be initialzed using set methed. After the object is initialized, print all fields' values of user object. Also print the number of days of birthMonth. ___________ 6a.2 Define EnumTest class, in main method: Iterate the Month enum (created in 6a.1) to print all months' names, ordinal value, and number of days of each month. Also iterate the Month enum to print a subset of months e.g. from Sep. to Dec. Create sub list of Month ...

How to Search Tweets using Twitter4j Java API

Image
In a recent SEO related project, I used Twitter4J Java API to download 3 million plus tweets. Below is the proof of concept code. There are only three major steps: 1. Download the latest Twitter4J JAR file from http://twitter4j.org/en/  and add into your project library or class path. 2. Create Twitter App by visting https://apps.twitter.com/ Click Create New App button and fill the form by providing app name, URL and app brief description and submit clicking on "Create New Twitter Applicaton" button. Once the application is created, click the application name on dashboard and go to Key and Access Toekn tab. There would see Consumer Key (API Key), Consumer Secret (API Secret). Click on Generate Access Token and Token secret button, it would generate Access Token and Access Token Secret. These 4 things are what you need when making the API call. 3. Just use below code, as-is, it shall fetch the tweets. Modify the code as per your requirements. Its self...

Java Program that Purchases a Computer from Datacenter in London and Install Ubuntu using Linode API

Image
Amazon AWS, Digital Ocean and Linode are well known cloud platform, infrastructure and other services providers. Below I explain how we can write a Java program that buys a computer from Linode London Datacenter, install Ubuntu OS and put it ON. Definitely, you can choose your datacenter of choice among following: Dallas, Fremont, Tokyo, London, Singapore, Frankfurt. I have selected London. Linode provide RESTful services to create and manage different resources e.g. linux box aka Linode, node balancers, setting DNS, IPs, Backup, Storage and scalling system resources. Below program use Linode RESTful API via official wrapper Java API. Lets move step by step: First of all, you must create an account at Linode.com. Login into your account, go to My Profile > API Keys and click on Create New API key. Note it down, we need it to make API calls. Download the Linode official Java API from  https://github.com/synapticloop/linode-api and add the linode-api.jar and runtime dependencie...

Assignment 4 - Point of Sale system

Develop a limited version of Point of Sale system. You have seen it already, its what a salesman use at medical or deparmentsal stores to make invoices. Making complete system is difficult at this level and need more time than we are left with. So build only following functionalities: (I recommend to save all data in MySQL database, DB lecture links already shared at FB Group, you can also use binay files, if you feel not comfortable with using MySQL after watching video lectures). Customers CRUD (Create, Retrieve, Update, Delete) and List functionality using Java GUI. Customer table and class shall have: id, name, email, gender, active, city, cellNumber Create means (provide short key: Ctrl+N), provide a JFrame based form to add new customer.  List means, show all customers ID-Name in JList, so that user could select the customer to perfrom Update, Show/Retrieve or Delete operation.  Update means, user shall be able to update the customer record. He shall select the custome...

Task 11: Java GUI Basics

Task 11.1: Make a form that shall look like this: Name: _____________ (Text field) Email: _____________ Gender: o Male    o Female   (radio button) Subjects: o OOP  o DB  o Web  o Android  o Machine Learning   [Check boxes]                 [ Submit ]            (submit button) Make a class User with name, email, gender and subjects instance attributes of type String, String, Boolean, and ArrayList<String>. When user fill above form and press the submit button, make an object of User using the form data and save that object on file using Serialization. When user run the program again, if user has saved the user object earlier, load the form with user existing data (explore some functions of Swing components using API docs and Googling). ~~~~~~~~~~~~~~~ Task 12 would be Assignment 4 and would be little complex using Swing programming. So make sure you have done task 11.

Task 10b - Interfaces and Exception Handling in Java

Create a UserService Interface with following methods. void addUser(User user) void updateUser(User user) void deleteUser(int userID) User getUser(int userID) void unblockUser(int userID) void blockUser(int userID) ArrayList<User> getAllUsers() Define InMemoryUserService class that shall implement UserService contract or interface. Use ArrayList for storage, update and retrieve operations inside InMemoryUserService i.e. you shall define a static attribute ArrayList<User> users = new ArrayList<>(); The implemented methods shall change/read this list to perform the required operation.  Test all methods from UserTest class. Getting information from user input is encourged but optional.  Define at least id, name, and status instsance attributes in User class of type int, String and Boolean. How you check whether a user account is blocked? If status attribute is false, it means user account is blocked. True represent the account is active. Make ...

Task 9 - Polymorphism in Java

9.1:  Make Circle , Rectangle , Square and Triangle classes that extends Shape.  Shape has color attribute and an abstract double calcArea() method. Circle has radius attribute. Triangle has base and height. Rectangle has length and width.  Square have only one attribute i.e. size (to represent width and height both, as both are same in case of square). In ShapeTest class's main method, ask the user how many shapes he want to create. Then, ask the type of each shape, then get the required data to instantiate that shape object. Keep putting each shape in ArrayList of type Shape . e.g. How many shapes you want to create: 4 Choose 1st Shape type: Press 1, to create Circle Press 2, to create Rectangle Press 3 to create Triangle Press 4 to create Square >1 Enter the radius of circle: > 5 .... .... Then outside the loop, display following information: Sum of area of each shape type  Total shapes of each shape type Total cost to paint each shape type  Cost t...