×
Reviews 4.9/5 Order Now

Implement The Use of Arrays and Characters in Java Assignment Solution

June 29, 2024
Jessica Miller
Jessica Miller
🇺🇸 United States
Java
Jessica Miller is a seasoned programmer with a master's degree in software engineering from Stanford University. Having completed over 700 Java assignments, Jessica excels in implementing sorting algorithms, multi-dimensional arrays, and efficient array operations. Her deep understanding of complex programming concepts and hands-on experience make her a valuable resource for students seeking high-quality homework help.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Understand the problem first, then choose the most suitable data structure—whether it's arrays, linked lists, stacks, queues, or trees. Practice drawing diagrams to visualize how data flows and test edge cases thoroughly to ensure your implementation handles all scenarios efficiently.
News
In early 2025, Intel’s Cryptography Primitives Library 2025.1.0 launched with optimized AES, RSA, and post-quantum algorithms (XMSS/LMS), making it ideal for students tackling assignments on secure communications

Instructions

Objective

Write a java assignment program to work with arrays and characters.

Requirements and Specifications

Program-to-work-with-arrays-and-characters-ADT-in-java

Screenshot

Source Code

QUESTION 1 package javatest; import javatest.exception.EndOfStreamException; import javatest.reader.CharacterReader; import javatest.reader.SimpleCharacterReader; import java.util.*; public class Q1 { public static void main(String[] args) { Map map = new HashMap<>(); StringBuilder builder = new StringBuilder(); CharacterReader reader = new SimpleCharacterReader(); try { while(true) { char c = reader.getNextChar(); if (Character.isAlphabetic(c)) { builder.append(builder.length() == 0 ? Character.toUpperCase(c) : Character.toLowerCase(c)); } else { if (builder.length() > 0) { map.merge(builder.toString(), 1, Integer::sum); builder = new StringBuilder(); } } } } catch (EndOfStreamException e) { if (builder.length() > 0) { map.merge(builder.toString(), 1, Integer::sum); } } List> pairs = new ArrayList<>(map.entrySet()); pairs.sort((o1, o2) -> { int diff = o2.getValue() - o1.getValue(); if (diff == 0) { return o1.getKey().compareTo(o2.getKey()); } return diff; }); for (Map.Entry pair : pairs) { System.out.println(pair.getKey() + " - " + pair.getValue()); } } } QUESTION 2 package javatest; import javatest.exception.EndOfStreamException; import javatest.reader.CharacterReader; import javatest.reader.SimpleCharacterReader; import javatest.reader.SlowCharacterReader; import java.util.*; public class Q2 { private static final Map map = new HashMap<>(); private static boolean[] completed; private static void printState() { List> pairs; synchronized (map) { pairs = new ArrayList<>(map.entrySet()); } pairs.sort((o1, o2) -> { int diff = o2.getValue() - o1.getValue(); if (diff == 0) { return o1.getKey().compareTo(o2.getKey()); } return diff; }); for (Map.Entry pair : pairs) { System.out.println(pair.getKey() + " - " + pair.getValue()); } } public static void main(String[] args) { int threadNum = 10; Thread[] threads = new Thread[threadNum]; completed = new boolean[threadNum]; for (int i = 0; i < threadNum; i++) { final int index = i; threads[i] = new Thread(() -> { CharacterReader reader = new SlowCharacterReader(); StringBuilder builder = new StringBuilder(); try { while (true) { char c = reader.getNextChar(); if (Character.isAlphabetic(c)) { builder.append(builder.length() == 0 ? Character.toUpperCase(c) : Character.toLowerCase(c)); } else { if (builder.length() > 0) { synchronized (map) { map.merge(builder.toString(), 1, Integer::sum); } builder = new StringBuilder(); } } } } catch (EndOfStreamException e) { if (builder.length() > 0) { synchronized (map) { map.merge(builder.toString(), 1, Integer::sum); } } completed[index] = true; } }); threads[i].start(); } long startTime = System.currentTimeMillis(); long seconds = 0; while(true) { boolean stop = true; for (boolean b : completed) { if (!b) { stop = false; break; } } if (stop) { break; } if ((System.currentTimeMillis() - startTime) / 1000 >= (seconds + 10)) { seconds += 10; printState(); System.out.println(); } } for (int i = 0; i < threadNum; i++) { try { threads[i].join(); } catch (Exception ignored) { } } System.out.println("Final:"); printState(); } }

Similar Samples

Explore ProgrammingHomeworkHelp.com for a preview of our expertly crafted programming assignment samples. From Java and Python to C++ and beyond, these examples showcase our proficiency in delivering precise solutions. Whether you're a student seeking clarity or a professional refining skills, our samples demonstrate our commitment to excellence in tackling programming challenges effectively."