Results 1 to 2 of 2

Thread: Help with code

  1. #1
    syphethia is offline Member
    Join Date
    May 2014
    Posts
    1
    Rep Power
    0

    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
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    448
    Rep Power
    1

    Default Re: Help with code

    Hi,

    I am just wondering: Did you try something already? We can only help you, when we know where you are stuck. If you are already stuck on creating a class, then I would suggest that you start completely at the beginning with a Java tutorial or a good beginners book. But you said that there was more assignments and you was able to solve others. So hopefully that is not your problem!

    Take one of these assignments, show us where you are stuck and ask questions that we can answer without solving the assignment. (And the first assignment already telly you what to do!)

    Konrad

Similar Threads

  1. Replies: 1
    Last Post: 03-25-2012, 02:40 AM
  2. Replies: 16
    Last Post: 01-31-2012, 08:36 PM
  3. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  4. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •