Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help with code.

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with code.

    So I have a final coming up and she gave us a practice test and there are two programming questions that I need help with. The first is

    MyArray Class (You can either use an array or an arrayList)
    Create a class called LastNameFirstNameMyArray according to the UML diagram. This class will allow a user to enter 5 integer values into an array(or object of ArrayList<Integer>). It contains methods to find min and max values and calculate the mean for the data set.

    LastNameFirstNameMyArray - data[ ] : int (or data : ArrayList<Integer> )
    - min : int
    - max: int
    - mean : double + LastNameFirstNameMyArray()
    + findMin() : void
    + findMax() : void
    + calculateMean(): void
    + toString() : String


    Attributes:
    • data[]—the array which will contain the values
    or data<Integer>—the arraylist which will contain the values
    • min—the minimum value among the values in the arraylist
    • max—the maximum value among the values in the arraylist
    • mean—the arithmetic average of the values

    Methods:
    You need to implement the constructor LastNameFirstNameMyArray(), which populates 5 values. In addition, the constructor should call findMin() and findMax(), and also calculateMean().
    Methods:
    • LastNameFirstNameMyArray()—the constructor. It will allocate memory for the array (or arraylist) of size 5. Use a for loop to repeatedly display a prompt for the user which should indicate that user should enter value 1, value 2, etc. Note: The computer starts counting with 0, but people start counting with 1, and your prompt should account for this. For example, when the user enters value 1, it will be stored in indexed variable 0. The constructor should populate 5 integer values, call findMin() and findMax(), and also calculateMean().
    • findMin()—this is a method that uses a for loop to access each data value in the array (or arraylist) and finds the minimum value. The minimum value is stored into min.
    • findMax()—this is a method that uses a for loop to access each data value in the array (or arraylist) and finds the maximum value. The maximum value is stored into max.
    • calculateMean()—this is a method that uses a for loop to access each data value in array (or arraylist) and add it to a running total. The total divided by the number of values (use the length of the array), and the result is stored into mean.
    • toString()—returns a String containing data, min, max, and the mean.


    Task #2 TestMyArray
    1. Create a LastNameFirstNameTestMyArray class. This class only contains the main method. The main method should declare and instantiate a LastNameFirstNameMyArray object.
    2. Compile, debug, and run the program. Then, it should print out the contents, the min, max, and mean of the data.


    and the second is

    A theater seating chart is implemented as two-dimensional array of ticket prices, like this:

    10 10 10 10 10 10 10 10 10 10
    10 10 10 10 10 10 10 10 10 10
    10 10 10 10 10 10 10 10 10 10
    10 10 20 20 20 20 20 20 10 10
    10 10 20 20 20 20 20 20 10 10
    10 10 20 20 20 20 20 20 10 10
    20 20 30 30 40 40 30 30 20 20
    20 30 30 40 50 50 40 30 30 20
    30 40 50 50 50 50 50 50 40 30

    Write a program that prompts the users to pick either a seat or price. Mark sold seats by changing the price the 0. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price.
    Note: Assume that if the user enters 1 for the row and 1 for the seat, the yellow marked sit will be sold.



    I was hoping someone could sorta walk me through these two questions and help me out like do a step by step.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help with code.

    We'll sorta help you with code that you've written. Take it a problem at a time and begin writing. Come back when you have code and questions. IF there's no way you can write a class, a main() method, the signatures of the required methods, and a few lines of code in the main() method to get started, then there's not much we can do for you.

Similar Threads

  1. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  2. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  3. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  4. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM

Tags for this Thread