• 0

[Java] Arrays, HW, and more


Question

Hey everyone, its been quiite a while since I have posted at Neowin, however, I am in dire need of help with two beginning Java assignments. I have been behind in my class due to some lame personal reasons so im a bit lost. If anyone can help me with any of this it would be awesome :)

I apologize if this is viewed as "someone else doing my work," as I am merely only trying to better understand what needs to be done to complete the assignments.

The first assignement is to write a complete Java program in a source file to be named Assignment5.java. This file must hold class Assignment5 which has just one method: main.

The program simulates a compass. The program prompts the user for the following menu:

1. Turn North

2. Turn South

3. Turn West

4. Turn East

5. Quit

and based on the user choice prints ^ , V, < , or > respectively. Your program should continue with the menu until the user chooses to quit (choice number 5). You are required to use at least one switch statement in this program.

Sample Output: The user input is in brackets[ ]

1. Turn North

2. Turn South

3. Turn West

4. Turn East

5. Quit

Please select a command:[1]

^

1. Turn North

2. Turn South

3. Turn West

4. Turn East

5. Quit

Please select a command:[3]

<

1. Turn North

2. Turn South

3. Turn West

4. Turn East

5. Quit

Please select a command:[5]

Link to comment
https://www.neowin.net/forum/topic/597885-java-arrays-hw-and-more/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

And now for the part where I have nooo clue where to start. :(

This assignment is to create a class called NumberCollection in a file called NumberCollection.java. (there is no main method in this class). A class NumberCollection has an array of integers and a count (integer) as instance variables. The variable count keeps track how many integers are store in the array. The variable name for the array of integers is numberArray.

Note: You need to distinguish the array size (capacity) and "count" that keeps track of numbers added to this array so far.

The class NumberCollection must include the following constructor and methods. (If your class does not contain any of the following methods, points will be deducted.)

Method

Description of the Method

public NumberCollection(int arraySize)

It constructs an empty NumberCollection object with an array capacity specified by the integer parameter "arraySize".

private int indexOf(int searchingNum)

It returns the index of the number specified by the parameter is located. If the number is not found, it returns -1. It is a service (helper) method.

public boolean addNumber(int numberToAdd)

The method checks if the integer specified by the parameter exists in the array (This can be done using the indexOf method to see if it returns -1 or not) and also checks if the array has not reached its capacity. If both are satisfied, the number is added to the array at the smallest available index. If the array reached its capacity, double its size by calling the method doubleArrayCapacity() and add the number. If the number is added successfully, then the method returns true. If the number already exists in the array, the new number will not be added, and the method returns false.

public boolean removeNumber(int numberToRemove)

The method checks if the integer specified by the parameter exists in the array (This can be done using the indexOf method to see if it returns -1 or not) and if it does, it moves the index stored in the last index (count-1) to where numberToRemove was found, and changes the content at the last index to 0 and return true. Otherwise, it returns false.

private void doubleArrayCapacity()

It is a service (helper) method and doubles the capacity of the numberArray. Please see the example in page 338, the method increaseSize() as a reference.

public int findMax()

It finds the maximum number among the numbers stored so far (at the time when this method is called), and returns it. If the array is empty, return 0.

public int findMin()

It finds the minimum number among the numbers stored so far (at the time when this method is called), and returns it. If the array is empty, return 0.

public int computeSum()

It computes and returns the sum of numbers stored in the numberArray so far (at the time when this method is called.) If the array is empty, return 0.

public String toString( )

Returns a String containing a list of numbers stored in the numberArray. An example of such string can be:

(3, 6, -1, 3, 23, -50, 43)

The string should start with a '(' and end with a ')'.

Save the NumberCollection class in a file called NumberCollection.java and use the following program stored in Assignment6.java, which has the main method to create new NumberCollection objects and to test your class.

The program will ask a user to enter a size for the array. Then it will show the following menu to a user:

Command Options

-----------------------------------

a: add an integer in the array

b: remove an integer from the array

c: display the array

d: compute and display the maximum

e: compute and display the minimum

f: compute and display the sum

?: display the menu again

Then it will ask a user to enter one of the above commands. Based on the user's choice, the program needs to perform corresponding operation. This will be done by using a method you defined in the NumberCollection class. The program will terminate when a user enters 'q'.

Any help, recommendations, or input is welcomed for both of these assignments.

Thanks everyone :)

  • 0

Start by creating the classes and by adding the required methods first.

(the methods dont have to do anything, just so you can get a picture of what your class looks like, better yet draw yourself some diagrams of the classes)

create a driver class that has a main, that will instigate/run your code.

you should post some code or attempt something before asking for help here.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Camtasia 2026.1.3 by Razvan Serea TechSmith Camtasia is the complete professional solution for high-quality screen recording, video editing and sharing. Camtasia 2026 makes editing your videos easier, and faster than ever. The new editor is packed with enhanced video processing, all-new production technology, an innovative library, and stock videos and other creative assets to help you create more polished, professional videos. No video experience needed. Anyone can create informative, engaging videos. Create professional, eye-catching videos: Add special video effects - Apply Behaviors that are perfectly designed to animate your text, images, or icons. Get a crisp, polished look without being a professional video editor. Drag-and-drop your edits - What you see is what you get. Every effect and element in your video can be dropped and edited directly in the preview window. And you can edit at resolutions up to beautiful 4K, for clear video at any size. Get exceptional performance - Camtasia takes full advantage of your computer’s processor with 64-bit performance. You’ll get fast rendering times and enhanced stability—even on your most complex projects. Camtasia 2026.1.3 changelog: Feature Updates Improved keyboard navigability in tool panels. Improved screen reader accessibility of headings in Preferences. Tool panels can now be resized using a keyboard-navigable control. Updated color of folder icon in User Library tab for better visibility. Grouped media now render a composite waveform considering all audio media within that group. Added Long Path Aware to the manifest of Editor and Recorder. Performance Improvements Improved performance for editing groups on the timeline. Improved the project loading performance when timeline has lots of trec media with cursor data. Updates for IT Administrators Updated cpp-httplib from 0.38.0 to 0.43.3. Updated expat from 2.7.4 to 2.8.0. Updated freetype from 2.13.3 to 2.14.3. Updated harfbuzz from 13.0.1 to 14.2.0. Updated libpng16 from 1.6.55 to 1.6.58. Updated pango from 1.57.0 to 1.57.1. Updated girepository from 2.86.3 to 2.88.0. Updated pcre2-posix from 10.47.0 to 12.0.2. Added new harfbuzz-gpu.dll. Updated FFmpeg from 7.1.1 to 7.1.2. Updated aom from 3.11.0 to 3.13.1. Updated dav1d from 1.5.0 to 1.5.1. Updated ogg from 1.3.5 to 1.3.6. Updated SDL2 from 2.32.4 to 2.32.10. Updated zlib from 1.3.1 to 1.3.2. Updated Nalpeiron binaries to version 4.4.69.3. Bug Fixes Fixed an issue which prevented some user submitted crash reports from being sent. Fixed a potential memory leak when decoding HEVC or VP9 video. Fixed a potential crash when trying to delete a range selection on a magnetic track. Fixed a bug with the Properties Panel showing stale properties when only a caption is selected on the timeline. Fixed an issue that could prevent the Opacity and Blur properties from being changed in the Background Removal effect. Fixed an issue where larger Camtasia online projects may fail to open in Camtasia Editor. Table of contents thumbnails are no longer created for Smart Player exports with no table of contents. Fix resetting skew revert to revert just skew and not scale as well. Fixed editing in Snagit with snagX file with Unicode characters. Fixed a bug where grouped visual media could be cropped in some cases. Fixed importing SnagX files with Unicode characters. Localization fixes. Download: Camtasia 2026.1.3 | 309.0 MB (Shareware) View: Camtasia Homepage | Tutorials | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • yeah it seems to be Edge only. The dialog buttons work as expected in Chrome and Firefox. The phone is using Android 16 (OneUI 8.5) and Edge version  149.0.4022.53
    • I'm not aware of this issue, but to help the other guys.  What version of Android are you using? Did you try a different browser? To see if Edge is the issue here.
    • I agree when are you going to read this (really poor BTW) article? Here is a better article so you actually know what is going on and answers questions you had in other comments --> https://arstechnica.com/gadgets/2026/05/speed-boosting-low-latency-profile-is-one-of-the-improvements-coming-to-windows-11/ It is unclear if one will be able to disable the new profile at this point but I am not seeing any reason why one would.
  • Recent Achievements

    • One Month Later
      Jamswaz earned a badge
      One Month Later
    • Week One Done
      Jamswaz earned a badge
      Week One Done
    • Rookie
      Marzoid went up a rank
      Rookie
    • Community Regular
      coch went up a rank
      Community Regular
    • One Year In
      slackerzz earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      510
    2. 2
      PsYcHoKiLLa
      188
    3. 3
      +Edouard
      156
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!