Posts

Showing posts with the label Algorithms

[SOLVED] Java How To Program | Shopping Cart Application | Chapter #29 Ex #29.4 Solution

Shopping Cart Application: Using the techniques you learned in Section 29.8.2, create a simple shopping cart application. Display a list of books as an h:selectOneRadio element. When the user submits the form, store the user’s selection in a @SessionScoped managed bean. Allow the user to return to the list of books and make additional selections. Provide a link to view the shopping cart. On the shopping cart page, display the list of selections the user made, the price of each book and the total of all books in the cart. Get your solution now Buy now

[SOLVED] Buggy Search And Sort Buy Reporting with Java source code

Report The Bug From The Following Source Code: import java.util.Arrays; /** * This class looks like it's meant to provide a few public static methods for * searching and sorting arrays. It also has a main method that tests the * searching and sorting methods. *  * TODO: The search and sort methods in this class contain bugs that can cause * incorrect output or infinite loops. Use the Eclipse debugger to find the bugs * and fix them */ public class BuggySearchAndSort { public static void main(String[] args) { int[] A = new int[10]; // Create an array and fill it with random ints. for (int i = 0; i < 10; i++) { A[i] = 1 + (int) (10 * Math.random()); } int[] B = A.clone(); // Make copies of the array. int[] C = A.clone(); int[] D = A.clone(); System.out.print("The array is:"); printArray(A); if (contains(A, 5)) { System.out.println("This array DOES contain 5."); } else { System.out.println("This array DOES NOT contain 5....

[SOLVED] Implementation of hash tables from scratch in Java with full source code

The fact that Java has a HashMap class means that no Java programmer has to write an implementation of hash tables from scratch -- unless, of course, you are a computer science student. For this exercise, you should write a hash table in which both the keys and the values are of type String. (This is not an exercise in generic programming; do not try to write a generic class.) Write an implementation of hash tables from scratch. Define the following methods: get(key), put(key,value), remove(key), containsKey(key), and size(). Remember that every object, obj, has a method obj.hashCode() that can be used for computing a hash code for the object, so at least you don't have to define your own hash function. Do not use any of Java's built-in generic types; create your own linked lists using nodes as covered in section 9.2.2 of the textbook. However, you do not have to worry about increasing the size of the table when it becomes too full. Get your project now  Buy now

[SOLVED] Tape for a Turing Machine using Doubly-linked List in Java with full source code

Tape for a Turing Machine (Doubly-linked List) Short exercise in which you will code part of an existing project. In this case, you will be working with a doubly-linked list. To make this topic more interesting, the list that you work on will be part of a Turing Machine. A Turing Machine is a kind of very simple, abstract computing device that was introduced in the 1930's by Alan Turing as a way of studying computation and its limitations. The classes that you need for the lab are in a package named turing. You will define a new class named Tape in this package. You can find the Java source in the code directory. You should copy this directory into an Eclipse project. There will be errors, since the existing classes depend on the Tape class, which you have not yet written. Don't forget the Javadoc comments. A Class for Turing Machine Tapes A Turing machine works on a "tape" that is used for both input and output. The tape is made up of little squares called cell...

[SOLVED] Java GUI project with toolbar and panels | Editing project with full source code

For this lab, you will do some work on a GUI program. Most of the work is related to actions, buttons, menus, and toolbars.When you turn in your work for this lab, you should also turn in an executable jar file of your program, in addition to all the files from your Eclipse project. See the last section on this page for information about how to create executable jar files. To begin the lab, create a new project in Eclipse and copy-and-paste both directories – guidemo and resources -- from the code directory into your Eclipse project. The guidemo directory is a package that contains the Java code of the program. The resources directory has several sub-directories that contain image and sound resources used by the program. You will be working only on the code in the guidemo package. The code directory also contains an executable jar file of the completed program, GuiDemoComplete.jar. You can run this jar file to see how the program should look when it's done. In the incomplete so...

[SOLVED] Travelling Salesman problem with full source code in Python | TSP project

Firstly, this worksheet is one of the worksheets from which your laboratory worksheets portfolio of work will be assessed. This worksheet is about empirically evaluating how scalable a number of single population heuristic search methods are at solving the Travelling Salesman Problem (TSP) when applied to a number of different sized problems. The aim is to evaluate and demonstrate how well each of the methods performs as the size of the problem increases. The overall objective of this worksheet is to produce; present and report on, a Java program that is capable of solutions the TSP on a number of different sized problems using a number of different heuristic search algorithms (see below). Solving the TSP Problem The Travelling Salesman problem (TSP) has been described fully in the lectures. The purpose of this worksheet is to: 1) Implement a number of the algorithms (listed below) to solve the TSP 2) Compare the algorithms on a number of different sized datasets 3) Report o...

[SOLVED] Implementing 8-puzzle search in java with full source code | download now

The 8-puzzle problem In this project you will implement a solution to the 8-puzzle by state-space search, using the search engine described in the lectures, and experiment with search strategies. 2. What you must do 2.1 Implementing 8-puzzle search In the search2 folder in the Java download on the COM1005/2007 MOLE site is the code for the simple search engine and for Jugs problems. Note that you may have to recompile the code for your version of Java. Following the instructions in section 2.9 of the lecture notes, write classes to implement a state-space search for 8-puzzle problems. You should not need to change the code for the search engine except perhaps to control how much it prints as a search proceeds, and to stop the search after a given number of iterations (in an 8-puzzle the search tree can become large). Test your implementation with breadth-first searches for the following initial con- figurations and the same goal state as above: 2.2 Experimenting with ...

[SOLVED] Algorithm to find that a given binary tree is also balanced tree (AVL Type)

AVL Tree Balance Tree Checker Algorithm: Design an algorithm which tests if an input binary tree is also balanced tree (AVL type). Prove algorithm's correctness and estimate its complexity. We're using appropriate format for the report according to the requirements Get your solution now  Buy now

[SOLVED] Cash Register program using Greedy Algorithm in Java with full source code

Program Formal Description: The driver class should initially fill the register with 0x$100, 0x$50, 10x$20, 20x$10, 20x$5, 0x$2, 50x$1, 80x$0.25, 50x$0.10, 20x$0.05, 100x$0.01 The program should ask the user the following: Make a sale make change print balances exit For a sale: the program class should prompt for the cost and how much of each type of currency were given If the register can not make the correct change, print an appropriate message For making change: the program should ask which currency is being provided and how much of that currency, then it should output what currency is being given example, make change, provide 4 quarters, register gives 1x$1 example, make change, provide 50 dimes, register gives 1x$5 OR 5x$1 OR 4x$1, 4x$0.25 For print balances, just show what is currently in the register of every currency Calculate Big-Oh for all 3 processes Calculate actual operations for making a sale and print out (don't forget to include the cost of usin...

[SOLVED] Dictionary Spell Checker Program in Java with full source code

Use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the set, if it is not already there. set.contains(item) -- Check whether the set contains the item. set.isEmpty() -- Check whether the set is empty. You will also need to be able to traverse a set, using either an iterator or a for-each loop. Reading a Dictionary The file words.txt (in the code directory) contains a list of English words, with one word on each line. You will look up words in this list to check whether they are correctly spelled. To make the list easy to use, you can store the words in a set. Since there is no need to have the words stored in order, you can use a...

[SOLVED] CSE2100 Project: Arithmetic Expressions Background | Postfix Notation Calculation | Java

Background The arithmetic expressions considered in this project consist of non-negative integers, operators "+", "-", and "*", and parentheses "(" and ")". Arithmetic expressions are usually written using the infix notation, in which operators appear between the two operands on which they act (e.g., "2 + 2"). The evaluation of expressions in infix notation is done according to the standard order of operations: multiplications must be done first, from left to right, then all additions and subtractions, again from left to right. Parentheses can be used to change the order in which operations must be performed, e.g., the expression inside the innermost parentheses must be evaluated first, etc. Since each of the considered operators takes exactly two operands, such an arithmetic expression can be represented as a proper binary tree whose internal nodes are associated with the expression's operators and whose leaves are as...

[SOLVED] Basic Linked List and Sorted Linked List with Java Unit Testing | Programming | Codding | Algorithm

Code Distribution The project's code distribution is available by checking out the project named LinkedListsProject. The code distribution provides you with the following: listClasses package → Where classes implementing linked lists will appear. tests package → Where you should place your student tests. Specifications You are expected to implement two classes: BasicLinkedList and SortedLinkedList.The javadoc describing what you need to implement can be found at Project Javadoc. The linked list in our project has a head and tail reference. The next link of the last node points to null. Methods addToEnd(), getLast(), retrieveLastElement() rely (and must use) the tail reference. The head and tail must be set correctly when list operations update the list. You can use recursion for the implementation of methods. Two methods must be implemented using recursion: getReverseArrayList() and getReverseList(). You are allowed to add an auxiliary function (only one) during ...

[SOLVED] Java Program to implement Radix Sort Algorithm and displaying the step by step sorting

Write a program for Radix Sort. The output of the program, apart from displaying the final result of the sorting algorithm, you also need to display the result of every round after one digit is sorted. Get the solution now! Get your solution now  Buy now

[SOLVED] Java Implementation of BST with parent node reference algorithm | Binary Search Tree

Implement the BST with parent node. Modify the insert and delete functions. Add the following functions too. private TreeNode<E getNode(E element) private boolean<E isLeaf(E element) public ArrayList<E getPath(E element) Get your solution now  Buy now

[SOLVED] Linked List project in Java | Addition at specific index | Reverse List | Remove Sorted and UnSorted

Java Code Extension Add the following methods to the list class on the file: public void addAt(int position, T item) The method adds an item at a given position.  The head has position 1, second item has position 2, etc. public void removeAllSorted(T item) The method removes all copies of the given item, assuming the list is sorted.   For example, if you have a list (1, 2, 2, 2, 3, 4) And you remove 2 So, the output for this method will be (1, 3, 4) public void removeAllUnsorted(T item) The method removes all copies of the given item, assuming the list is not sorted.   For example, if you have a list (2, 3, 4, 2, 1, 2) And you remove 2 So, the output for this method will be (3, 4, 1) public void reverseList() The method reverses the list.  For a sorted list, reversal would result in a list reversely sorted. For example, if you have a sorted list (1, 2, 3, 4, 5, 6) So, the output for this method will be (6, 5, 4, 3, 2, 1) For implementat...

[SOLVED] Recursively printing data in java full source code with output screenshot of running program

Write a recursive method that produces an output similar to the following: This was written by call number 1. This was written by call number 2. This was written by call number 3. This was written by call number 4 This was ALSO written by call number 4. This was ALSO written by call number 3 This was ALSO written by call number 2. This was ALSO written by call number 1. Get your solution now  Buy now

[SOLVED Intelligent Random Number Generator - 7 Unique numbers in Java with full source code

A walk through of how it would work is a follows. Generate seven unique numbers from 1 - 49 that meet the criteria selected by the user. Odd/Even Combination (first criteria and only one can be selected) for example 4 of them should be odd numbers and 3 of them even numbers (or the other options) Second Criteria is the High/Low combination - High(numbers from 26-49 and Low(numbers 1-25) is this option more than can be selected such as a) 3 of them must be High from 26 - 49 and 4 of them must be Low from 1-25, b) You can also have 4 of them be High from 26-49 and 3 of them Low from 1-25 NB High/Low are check boxes allowing for one or all of the characteristics to be selected. Total Sum presents a situation where the sum of the seven numbers must fall in line with one of the options, a) for example when you sum the 7 numbers it must from 150-200 (or the other options) The other scenario is for exclusions, the numbers are from 1-49 but there is an option where you can exclude som...

[SOLVED] Binary Sort Tree with all the features like depth of tree with 1023 nodes

In Subsection 9.4.2, the textbook (http://math.hws.edu/javanotes/) says that "if the [binary sort] tree is created by inserting items in a random order, there is a high probability that the tree is approximately balanced." For this exercise, you will do an experiment to test whether that is true. In the Introduction to this Learning Guide, you read that the depth of a node in a binary tree is the length of the path from the root of the tree to that node. That is, the root has depth 0, its children have depth 1, its grandchildren have depth 2, and so on. In a balanced tree, all the leaves in the tree are about the same depth. For example, in a perfectly balanced tree with 1023 nodes, all the leaves are at depth 9. In an approximately balanced tree with 1023 nodes, the average depth of all the leaves should be not too much bigger than 9. On the other hand, even if the tree is approximately balanced, there might be a few leaves that have much larger depth than the average, s...

[SOLVED] Radix Sort - Pseudocode, UML, code, test I/O in Java with complete source code

Domain Description Radix sorting entails grouping number elements in a data structure by each digit. First one groups by 1s; then 10s; then 100s (or the other way around; think little or big endian); and so on. Build a method that effectively models this behavior. You may use the code provided in Lafore, provided you are writing pseudocode, making comments, testing and capturing output and crafting UML. A part of this implementation entails determining the greatest number of digits, to effectively pad smaller elements with zeroes. You may use either an array or a linked structure comprised of nodes. Get your solution now  Buy now

[SOLVED] Train Track Allocation and Track Reader program with Test Cases in Java

Goal: The goal of this assignment is to gain practical experience with procedural abstraction – how complex functionality can be broken up into different methods and different classes.   Problem Overview:  In this assignment, you will continue to implement the component classes of a program for simulating the behaviour of a train management system.   Task Overview: In brief, you will write a method for reading in the sections of a track from a file, and you will write a method for allocating routes to trains (so that they don’t collide). If you are a CSSE7023 student you will also be required to write a JUnit4 test suite for testing the track-reading method. More specifically, you must code method read from the TrackReader class and method allocate from the Allocator class that are available in the zip file that accompanies this handout, according to their specifications in those files. If you are a CSSE7023 student, you will also need to complete a systematic and under...