Programming Project 1 - Object-Oriented Programming and Design | C SC 335, Study Guides, Projects, Research of Computer Science

Material Type: Project; Professor: Mercer; Class: Object-Oriented Programming and Design; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Fall 2000;

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/31/2009

koofers-user-j5o-1
koofers-user-j5o-1 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C Sc 335 Programming Project #1 To be completed in 228 GS
Due Date: Thursday, 4-Sep @ 10:00 p.m. 20 points
Collaboration: Complete this by yourself. You may get help from Section Leaders or Rick
Goals:
Get familiar with the integrated development environment (Eclipse) in Guld Simpson 228
Running a Java program as a class with a main method.
Write a Java class (or two)
0. Prerequisites
Establish your CS computers accounts (follow arrows on 7th floor Gould Simpson)
Obtain your lab access card (down the hall)
Read the lab rules
You are in the lab (228GS)
1. Logon
Move the mouse or type any key to wake up the monitor. Type CTRL-ALT-DEL. The legal notice will be
displayed. Read it. Click OK or press Return. This will bring up the logon window. Enter your username
and password. Then click OK or press Return. If you have problems logging on, check that your
username and password are correct and that the CSC domain is chosen (if this last option doesn’t show,
click Options >>). Check that caps lock is not on and use the digits across the top of the keyboard, not on
the keypad. The first time you logon, you will be required to change your password from the first six (6)
digits of your student ID to something else. The password you choose should be something hard to guess.
It must be at least 6 characters long and should contain 3 of the 4 following character groups: lower case
letters, upper case letters, digits, special characters (punctuation). Your name or username should not be
part of your password. The new password will have to be entered twice for confirmation.
2. Log off
Click on the Start button normally found in the bottom left corner of the screen. Choose Log Off
username. Click Yes. Don’t Shut Down or Restart the computer. Alternately, type CTRL-ALT-DEL,
choose Logoff, and click OK.
3. Logon Again
Use the directions above to log on with your new password.
4. Start Up Eclipse
Double click on the Eclipse icon on your desktop.
Eclipse.lnk
5. Create a New Java Project and Run a Class
Select the menu item File > New > Project.... to open the New Project wizard.
On the left pane of the first wizard page, select Java, and on the right pane, select Java Project. Then
click Next.
Enter the project name as 0_SectionLeaderName_YourLastName_YourFirstName
oExamples (use upper case letters for all names, folder will be under H:\workspace)
0_Adam_Mercer_Rick
0_Laura_Nelson_Kellen
Click Finish.
pf3
pf4
pf5

Partial preview of the text

Download Programming Project 1 - Object-Oriented Programming and Design | C SC 335 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

C Sc 335 Programming Project #1 To be completed in 228 GS

Due Date: Thursday, 4-Sep @ 10:00 p.m. 20 points

Collaboration: Complete this by yourself. You may get help from Section Leaders or Rick

Goals:

● Get familiar with the integrated development environment (Eclipse) in Guld Simpson 228

● Running a Java program as a class with a main method.

● Write a Java class (or two)

0. Prerequisites

● Establish your CS computers accounts (follow arrows on 7th floor Gould Simpson)

● Obtain your lab access card (down the hall)

● Read the lab rules

● You are in the lab (228GS)

1. Logon

Move the mouse or type any key to wake up the monitor. Type CTRL-ALT-DEL. The legal notice will be

displayed. Read it. Click OK or press Return. This will bring up the logon window. Enter your username

and password. Then click OK or press Return. If you have problems logging on, check that your

username and password are correct and that the CSC domain is chosen (if this last option doesn’t show,

click Options >> ). Check that caps lock is not on and use the digits across the top of the keyboard, not on

the keypad. The first time you logon, you will be required to change your password from the first six (6)

digits of your student ID to something else. The password you choose should be something hard to guess.

It must be at least 6 characters long and should contain 3 of the 4 following character groups: lower case

letters, upper case letters, digits, special characters (punctuation). Your name or username should not be

part of your password. The new password will have to be entered twice for confirmation.

2. Log off

Click on the Start button normally found in the bottom left corner of the screen. Choose Log Off

username. Click Yes. Don’t Shut Down or Restart the computer. Alternately, type CTRL-ALT-DEL,

choose Logoff , and click OK.

3. Logon Again

Use the directions above to log on with your new password.

4. Start Up Eclipse

Double click on the Eclipse icon on your desktop.

Eclipse.lnk

5. Create a New Java Project and Run a Class

● Select the menu item File > New > Project.... to open the New Project wizard.

● On the left pane of the first wizard page, select Java , and on the right pane, select Java Project. Then

click Next.

 Enter the project name as 0_SectionLeaderName_YourLastName_YourFirstName

o Examples (use upper case letters for all names, folder will be under H:\workspace)

 0_Adam_Mercer_Rick

 0_Laura_Nelson_Kellen

● Click Finish.

Confirm the switch to the Java perspective. Eclipse should look something like this now.

● Close Welcome.html by clicking on the X in the tab in its left hand corner.

If things worked out correctly, your H: drive should have a folder named workspace\First. Verify this by

opening an Explorer window and examining your H:\ drive.

● Add a new class to your project File > New > Class and enter Hello as the class name, also click the

checkbox to main method stub (bottom of dialog box).

 Click Finish

You should see a new editor window with a class preceded by comments "/*" and javadoc comments

"/**". These are automatically generated along with the class name, a main method stub, and non-

aligned curly braces. All of this behavior can be modified with a different default behavior (more in this

later). Add the println message to the main method

  • Created on Aug 26, 2003
  • To change the template for this generated file go to
  • Window>Preferences>Java>Code Generation>Code and Comments / /*
  • @author mercer
  • To change the template for this generated type comment go to

1. Set x = 81.

2. Set approximation = x / 2

3. Make five more approximations using this formula that gets closer to the square root (do not use

the Java's Math.sqrt method).

approximation ( approximation  x / approximation )/ 2. 0

4. Display the value of x and the approximation. Output should look like this

The square root of 81.0 is approximately 9.

8. Write a class to maintain Bowling Scores

In this lab, you are asked to add the JUnit library so you can use this testing framework. So first create a

new project, but this time after you enter the Project Name, click next to get to the Java Settings dialog.

 Select the following: File > New > Project > Java > Java Project > Next

 Enter the project name as 1_SectionLeaderName_YourLastName_YourFirstName

o Examples (use upper case letters for all names, folder will be under H:\workspace)

 1_Adam_Mercer_Rick

 1_Laura_Nelson_Kellen

 Click Next (NOT Finish)

 Click the Libraries Tab

 Click Add External JARs

 Browse to C:\Program Files\junit3.8.

 Click on junit.jar

 Click Open

 Click Finish

You will have to perform these extra steps for all projects. If you forget to do this with a new project, you

can always add JUnit at any point with these steps (you may skip these steps if JUnit is found).

 Project > Properties > Project Build Path > Libraries > Add External JARs

 Browse to wherever you JUnit was unzipped (may differ at home) and Click on junit.jar

 Click Open, Click Finish

The Specification for the Class You are to Write (finally)

The requirements for the class you are asked to write is defined by the tests in a class named

BowlingLineTest. You needed to take notes in class about how to score a line of bowling (it's a bit

tricky). Here is a picture of one line of bowling as a review.

Create class BowlingLine so the all tests in BowlingLineTest.java pass (turnin instructions follow).

// For C Sc 335 project 1: Make the following tests pass import junit.framework.*; public class BowlingLineTest extends TestCase { private BowlingLine g; // The setUp method executes before each and every method in this // class that begins with test and has 1 or more characters after test. public void setUp() { g = new BowlingLine (); // Create a new line to score bowling }

public void testTwoThrowsNoMark() { g.pinsDowned(5); g.pinsDowned(4); assertEquals(9, g.scoreAtFrame(1)); } public void testFourThrowsNoMark() { g.pinsDowned(7); g.pinsDowned(2); g.pinsDowned(5); g.pinsDowned(4); assertEquals(18, g.scoreAtFrame(2)); } public void testSimpleSpare() { g.pinsDowned(3); g.pinsDowned(7); g.pinsDowned(3); assertEquals(13, g.scoreAtFrame(1)); } public void testSimpleFrameAfterSpare() { g.pinsDowned(3); g.pinsDowned(7); g.pinsDowned(3); g.pinsDowned(2); assertEquals(13, g.scoreAtFrame(1)); assertEquals(18, g.scoreAtFrame(2)); assertEquals(18, g.scoreSoFar()); } public void testSimpleStrike() { g.pinsDowned(10); g.pinsDowned(3); g.pinsDowned(6); assertEquals(19, g.scoreAtFrame(1)); assertEquals(28, g.scoreSoFar()); } public void testPerfectGame() { for ( int i = 0; i < 12; i++) g.pinsDowned(10); assertEquals(300, g.scoreSoFar()); } public void testEndOfArray() { for ( int i = 1; i <= 9; i++) { g.pinsDowned(0); g.pinsDowned(0); } g.pinsDowned(2); g.pinsDowned(8); // 10th frame spare g.pinsDowned(10); // Strike in last position of array. assertEquals(20, g.scoreSoFar()); }