Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439

This assignment is about loops arrays. You will write three methods to manipulate arrays. The first two are easy. The third one will require more thought about the design. You will submit the assignment using the CSE give system (see below).

Download the BlueJ project, . It contains three methods. You have to write the code that goes inside them.

Question 1

The first method finds the average of the elements of an integer array:

public double average(int[] data)

That is, given an integer array, data, calculate what the average of its elements are and return the average value. For example, the average of {1, 3, 2, 5, 8} is 3.8.

Question 2

The second method is:

public int countInRange(int[] data, int lo, int hi)

For this, you have to count the number of elements of the array, data, that lie in the range lo to hi inclusive, and return the count. For example, if data is the array {1, 3, 2, 5, 8} then the call

countInRange(data, 2, 5)

should return 3 because there are three elements, 3, 2 and 5 that lie in the range 2 .. 5.

Question 3

The third method, arrayAdd, takes two arrays as parameters and returns a new array that is the sum of the first two.

public int[] arrayAdd(int[] R1, int[] R2)

The addition of two arrays yields an array whose elements are the sum of the corresponding elements in the parameter arrays, i.e.

R1[0] + R2[0], R1[1] + R2[1], R1[2] + R2[2], ....

R1 and R2 must be of equal length. Your code must test that they are the same length and output an error message, e.g. “The arrays must be the same length”.

Submission instructions

You will submit your assignment to the Give automated marked system.

  1. From within your assignment 1 BlueJ project, select Project -> Create Jar File…
  2. In the Dialog Box that appears:
    1. Set “Main Class” to none
    2. Ensure “Include Source” is checked
    3. Leave “Include Bluej project files” unchecked
  3. Press “Continue”
  4. Save the filename as “Assignment1.jar”
  5. Open a web browser and go to 
  6. Log-in with you Z-Pass
  7. Either enter “COMP1400″ in for the course, or select COMP1400 from the drop down menu and press “Search for Assignments”. Note INFSi1609/2609 students may need to enter “COMP1400″ instead of selecting the course form the dropdown
  8. Select “assignment1″ from the next drop down menu and press “Upload my Assignment”
  9. Accept the student declaration
  10. Press “Choose File” and select the “Assignment1.jar” file that you saved in step 4
  11. Press “Submit my Files”
  12. Wait for the page to completely load. Then carefully read the output. If the assignment is successful you should see the following lines:
    ================================================Checking your submission...Checking for Assignment1.javaAssignment1.java Compiled SucessfullyAll files are OK================================================
  13. If the page doesn’t load properly, that is OK just submit the assignment file again.
  14. If you don’t get the above output check the output to see what went wrong and resubmit.

Submission notes:

  1. You can submit as many times as you wish, even after the deadline. Only your last submission will be marked.
  2. Make sure you name everything the as instructed, including the classes and the submission file or the submission will not work.
  3. If you have any problems with submission, email 

 

Posted by on August 10th, 2014 ·

Feedback on your progress

Each week, we will post several short quiz questions to encourage you to do some preparation before the lab. The intention of the quizzes is to give you quick feedback so that you know if you understand the material in the course so far and to encourage you to prepare for the labs by reading over the lecture material from the previous weeks.

You should attempt the quizzes in your own time before the lab and bring your answers to your tutor, who will give you feedback. For now, quizzes are voluntary and we hope you’ll try them.

This week’s quiz is .

Lab Exercises

This week’s lab exercises are concerned with data types, which were introduced in last week’s lectures. You should attempt the exercises below using the  project for BlueJ.

Data types

What data type would you use to represent the following values? Why?

  1. The length of a piece of string.
  2. The number of students at UNSW.
  3. A person’s age.
  4. The mass of the sun.
  5. The exact number of stars in the Milky Way.
  6. The mathematical constant π.

Expressions

What are the value and type of the following expressions? Work these out on paper and then test your answers by typing them into the Code Pad in BlueJ. Can you explain the result?

  1. 5 / 2
  2. 5 % 2
  3. 5.0 / 2
  4. 5 / 2.0
  5. 5.0 / 2.5
  6. 5.0f / 2
  7. 1.5 % 1
  8. 1 / 0
  9. 1.0 / 0
  10. 10000000000 + 1
  11. 10000000000L + 1
  12. 10000000000.0 + 1
  13. 10000000000.0f + 1
  14. int x = 10;
  15. x = x + 2;
  16. int y = 3;
  17. int z = x + y + 1;
  18. x = x+ 2;

Circle area

The circleArea method in the Tut3 class calculates the area of a circle with a given radius.

Hand shaking

If there are five people Alan, Bel, Cameron, Dan, and Emily in the room and they each have to shake hands with everyone else, how many handshakes occur? What if there were 10 people? What if there were only two? Work out a general formula.

Complete the ‘handshakes’ method in the Tut3 project to use your formula to compute the number of handshakes for a given size group.

The Math Class

For more complicated mathematical expressions, Java has a lot of built in methods in the Math class. Take a look at the  to see what is available. Try typing the following
in CodePad. Explain the results.

If-statements

Assume we have declared an integer variable x. Write an if-statement that will print “one” if the value of x is 1, “two” if the value of x is 2 and “something else” if the value x is some other value.

Posted by on July 30th, 2014 ·

There are three tasks for this week’s lab:

  1. Activate your CSE account.
  2. Write your first program!
  3. Play with BlueJ

Activate your CSE account

The first thing we will do in this week’s lab is activate your CSE account, if you haven’t done so already.

  1. Login as ‘newuser’
  2. Follow the prompts to activate your account.
  3. Write your new username and password somewhere so you don’t lose it.
  4. Log out.
  5. Click on the ‘Session’ button on the login screen.
  6. Select ‘Gnome’.
  7. Login with your new username and password. (Sometimes it can take up to 30mins for your account to be activated. If this is the case, complete the next activity and then come back to this step.)
  8. When asked, click ‘Make Default’.

Write your first program.

This is an exercise in breaking down a task into a sequence of simple instructions. Work in pairs. Your tutor will give each of you a small, incomplete pack of cards.

  1. Shuffle the deck.
  2. Go through the deck to find the smallest card.
  3. On a sheet of paper, write a set of instructions so that someone else can repeat the same procedure. Assume that they are very stupid and need to have ever last detail spelled out.
  4. Test your instructions on different size decks:
    • What if there is only 2 cards in the deck? Or only one? Or none?
    • What if all the cards in the deck were the same?
  5. Swap programs with another pair and check their code. Was it the same as yours?
  6. Consider: What are the objects in your program? What are the classes? What fields do they have? What methodsdo they provide?
  7. Now try writing instructions to sort the entire deck into order.

Experiment with BlueJ

Experiment with the BlueJ projects we saw in lectures.

  1. Login with your CSE login and password set up earlier
  2. Download the 
  3. Unzip this file to create the BlueJ project.
  4. Start BlueJ
  5. Select ‘Open Project’ from the File menu and open the ‘Turtle’ project.
  6. Create a new ‘MyTurtle’ object by right clicking on the MyTurtle class and selecting new MyTurtle()
  7. Give your turtle a name and press OK.

Simple shapes

  1. Right click on the red MyTurtle object and select the void drawSquare(int sideLength) method.
  2. Enter a side length of 100 and press OK.
  3. Observe what happens in the World window.
  4. Try drawing squares of different sizes.
  5. What direction does the turtle face before and after you call the method?
  6. Double-click on the MyTurtle class to open the source-code.
  7. Read the drawSquare method. Can you explain why the turtle has a different direction after the method is called?
  8. What could you do to fix this so the turtle is facing the same way before and after the method?
  9. Change the code so that it draws a triangle instead of a square.

Using the debugger

  1. Read the method drawPolygon and try to understand how it works.
  2. Run it with different parameters to see if it does what you expect.
  3. In the source window, click on the line number for the line “if (numberOfSides < 3) {“. A little red stop sign should appear.
  4. Run the method again with numberOfSides set to 6 and sideLength set to 100. The Debugger window should appear.
  5. Press the Step button and watch how the program steps through the code.
  6. Run the method again with numberOfSides set to 2. Can you predict what will happen?

Spirals

  1. Read the method drawSpiral and try to understand how it works.
  2. Try drawing a spiral with length = 10 on a piece of paper following these instructions.
  3. Use the debugger to step through the method. Does it do what you expected?
  4. Change the line ‘length = length – 2‘ to ‘length = length – 4‘. How will this change the spiral? Run it and see.
  5. Change the line to ‘length = length + 4‘. What happens now? Why?

 

Posted by on July 9th, 2014 ·

This course introduces you to the foundations of the programming discipline, which underlies most technical subjects such as software design, data management and algorithms. It will involve both a theoretical component (e.g. learning about basic programming concepts like loops, arrays and functions) as well as a practical component (e.g. implementing simple algorithms in a computer laboratory). The course also provides a first step towards learning the principles of object-oriented design and programming through the use of the Java programming language.

The course is suitable for students with no prior programming experience. It is particularly targeted at IS students as it relates to a number of core concepts that are essential in understanding the technologies behind information systems in business without getting overmuch into low-level technical details.

All students should ensure they have read the .


Posted by on November 19th, 2013 ·

To clarify, you may not bring an A4 sheet of reference notes into the written exam. This exam is different to the practical ones. If you need to know specific details from the class libraries, the documentation will be provided in the exam.

We do however assume that you remember the fundamental and commonly used methods for ArrayList’s

Posted by on November 12th, 2013 · ,

Assignment 3 marks and tutor comments can be collected from the 

Posted by on November 5th, 2013 · ,

Assignment 2 marks and tutor comments can be collected from the

Posted by on October 25th, 2013 ·

The Weekly Quizzes held in labs have been and are also linked from the side bar.

Posted by on October 21st, 2013 ·

Marks for the mid-semester practical exam can be accessed at: .
INFS Students will need to enter “COMP1400” for the course code.

This page also contains marks for labs, quiz’s and assignments. However please note that not all marks have been uploaded.

Update: Your marked exam can now be collected from the . Select “midsem” from the list of assignments and press “Collect my assignment”.  INFS Students will need to enter “COMP1400” for the course code.

Posted by on October 20th, 2013 · ,

Don’t forget that the prac exam will be held in the regular lab times in week 13. This is compulsory and comprises 20% of your marks. It will have the same format as the mid-semester prac exam, except that you’ll have the full two hours.

Like the mid-semester exam, you will be allowed to bring one A4 page of notes to help you.