java Quarterback class
Here's my program, I need to fill in the blank methods and can't figure them out. I'm using JAVA object oriented. Please help, I'm new to this so I'm kind of confused. If someone could just help me out it will be awesome, just a little help is better than none.
Description
For this program, you are to create a Quarterback class. This is a simple object that represents a quarterback in the NFL. Implement the UML diagram given below. You may create additional private methods that you feel are necessary or helpful to implement this class.UML Diagram:
Create a Quarterback class based on the following UML diagram.-- attempts : int The number of passing attempts made by this Quarterback.
-- completions : int The number of passing completions made by this Quarterback. -- firstName : String This Quarterback’s first name. -- interceptions : int The number of interceptions thrown by this Quarterback. -- lastName : String This Quarterback’s last name. -- touchdowns : int The number of touchdowns thrown by this Quarterback -- yards : int The number of passing yards this Quarterback has.- Quarterback () Creates a new Quarterback object.
- Quarterback (String first, String last, int completions, int attempts, int yards, int interceptioiinint int touchdowns) Creates a new Quarterback object with the given parameters.
- copy() : Quarterback Returns a Quarterback object whose properties are identical to this Quarterback’s properties.
- equals(o : Object) : boolean Returns true if o is a Quarterback and o’s first name, last name, attempts, completions, yards, interceptions and touchdowns are all equal to this Quarterback’s corresponding properties.
- getAttempts() : int Returns this Quarterback’s number of passing attempts.
- getCompletions() : int Returns this Quarterback’s number of completions.
- getFirstName() : String Returns this Quarterback’s first name.
- getInterceptions() : int Returns this Quarterback’s number of interceptions.
- getLastName() : String Returns this Quarterback’s last name
- getRating() : double Returns this Quarterback’s NFL passer rating. The formula for NFL passer rating can be found at: http://en.wikipedia.org/wiki/Passer_rating.
- getTouchdowns() : int Returns this Quarterback’s number of touchdowns
- getYards() : int Returns this Quarterback’s number of passing yards.
- setAttempts(attempts : int) Sets this Quarterback’s attempts to attempts.
- setCompletions(completions : int) Sets this Quarterback’s completions to completions.
- setFirstName(name : String) Sets this Quarterback’s first name to name.
- setInterceptions(interceptions : int) Sets this Quarterback’s interceptions to interceptions.
- setLastName(name : String) Sets this Quarterback’s last name to name.
- setTouchdowns(touchdowns : int) Sets this Quarterback’s touchdowns to touchdowns.
- setYards(yards : int) Sets this Quarterback’s yards to yards.
- toString() : String Returns a String representation of this Quarterback consisting of the first name, a space, the last name, and this Quarterback’s passer rating displayed to one decimal. E.g., if q is a Quarterback object, q.toString() will return: “Aaron Rodgers 123.8”
/*
* Dakota Dao
* Quarterback class
* march 2011
*/
package quarterback;
public class Quarterback
{
private int attempts;
private int completions;
private String firstName;
private int interceptions;
private String lastName;
private int touchdowns;
private int yards;
//****************************************************************
public Quarterback( String firstName,
String lastName,
int completions,
int attempts,
int yards,
int interceptions,
int touchdowns )
{
}
//*****************************************************************
public void copy ()
{
}
//*****************************************************************
public void equals()
{
}
//*****************************************************************
public int getAttempts()
{
return this.attempts;
}
//*****************************************************************
public int getCompletions()
{
return this.completions;
}
//*****************************************************************
public String getFirstName()
{
return this.firstName;
}
//*****************************************************************
public int getInterceptions()
{
return this.interceptions;
}
//*****************************************************************
public String getLastName()
{
return this.lastName;
}
//*****************************************************************
public void getRating()
{
}
//*****************************************************************
public int getTouchdowns()
{
return this.touchdowns;
}
//*****************************************************************
public int getYards()
{
return this.yards;
}
//*****************************************************************
public void setAttempts(int attempts)
{
this.attempts = attempts;
}
//*****************************************************************
public void setCompletions(int completions)
{
this.completions = completions;
}
//*****************************************************************
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
//*****************************************************************
public void setInterceptions(int interceptions)
{
this.interceptions = interceptions;
}
//*****************************************************************
public void setLastName(String lastName)
{
this.lastName = lastName;
}
//*****************************************************************
public void setTouchdowns(int touchdowns)
{
this.touchdowns = touchdowns;
}
//*****************************************************************
public void setYards(int yards)
{
this.yards = yards;
}
//*****************************************************************
public String toString()
{
}
}
Here's the pre-programmed driver:
package quarterback;
public class QBTester {
public static void main(String[] args) {
// Create a Quarterback
Quarterback qb = new Quarterback ();
// Test OK quarterback
qb.setFirstName("qb");
qb.setLastName("ok");
qb.setAttempts(465);
qb.setCompletions(272);
qb.setYards(2972);
qb.setTouchdowns(18);
qb.setInterceptions(12);
if ("qb ok 79.6".equals(qb.toString())) {
System.out.println("Passed OK QB");
} else {
System.out.println("Failed OK QB");
System.out.println("Expected: qb ok 79.6");
System.out.println("Got: " + qb);
}
// Test max quarterback
qb.setFirstName("qb");
qb.setLastName("max");
qb.setAttempts(100);
qb.setCompletions(78);
qb.setYards(1275);
qb.setTouchdowns(12);
qb.setInterceptions(0);
if ("qb max 158.3".equals(qb.toString())) {
System.out.println("Passed max QB");
} else {
System.out.println("Failed max QB");
System.out.println("Expected: qb max 158.3");
System.out.println("Got: " + qb);
}
// Test completions too high
qb.setFirstName("qb");
qb.setLastName("comp2hi");
qb.setAttempts(100);
qb.setCompletions(78);
qb.setYards(1000);
qb.setTouchdowns(7);
qb.setInterceptions(5);
if ("qb comp2hi 110.8".equals(qb.toString())) {
System.out.println("Passed completions too high");
} else {
System.out.println("Failed completions too high");
开发者_运维百科 System.out.println("Expected: qb comp2hi 110.8");
System.out.println("Got: " + qb);
}
// Test completions too low
qb.setFirstName("qb");
qb.setLastName("comp2low");
qb.setAttempts(100);
qb.setCompletions(25);
qb.setYards(1000);
qb.setTouchdowns(7);
qb.setInterceptions(5);
if ("qb comp2low 71.3".equals(qb.toString())) {
System.out.println("Passed completions too low");
} else {
System.out.println("Failed completions too low");
System.out.println("Expected: qb comp2low 71.3");
System.out.println("Got: " + qb);
}
// Test completions 0
qb.setFirstName("qb");
qb.setLastName("comp0");
qb.setAttempts(100);
qb.setCompletions(30);
qb.setYards(1000);
qb.setTouchdowns(7);
qb.setInterceptions(5);
if ("qb comp0 71.3".equals(qb.toString())) {
System.out.println("Passed completions 0");
} else {
System.out.println("Failed completions 0");
System.out.println("Expected: qb comp0 71.3");
System.out.println("Got: " + qb);
}
// Test yards too high
qb.setFirstName("qb");
qb.setLastName("yards2hi");
qb.setAttempts(100);
qb.setCompletions(50);
qb.setYards(1275);
qb.setTouchdowns(7);
qb.setInterceptions(5);
if ("qb yards2hi 98.3".equals(qb.toString())) {
System.out.println("Passed yards too high");
} else {
System.out.println("Failed yards too high");
System.out.println("Expected: qb yards2hi 98.3");
System.out.println("Got: " + qb);
}
// Test yards too low
qb.setFirstName("qb");
qb.setLastName("yards2low");
qb.setAttempts(100);
qb.setCompletions(50);
qb.setYards(250);
qb.setTouchdowns(7);
qb.setInterceptions(5);
if ("qb yards2low 58.8".equals(qb.toString())) {
System.out.println("Passed yards too low");
} else {
System.out.println("Failed yards too low");
System.out.println("Expected: qb yards2low 58.8");
System.out.println("Got: " + qb);
}
// Test yards 0
qb.setFirstName("qb");
qb.setLastName("yards0");
qb.setAttempts(100);
qb.setCompletions(50);
qb.setYards(300);
qb.setTouchdowns(7);
qb.setInterceptions(5);
if ("qb yards0 58.8".equals(qb.toString())) {
System.out.println("Passed yards 0");
} else {
System.out.println("Failed yards 0");
System.out.println("Expected: qb yards0 58.8");
System.out.println("Got: " + qb);
}
// Test td too high
qb.setFirstName("qb");
qb.setLastName("td2hi");
qb.setAttempts(100);
qb.setCompletions(50);
qb.setYards(1000);
qb.setTouchdowns(14);
qb.setInterceptions(5);
if ("qb td2hi 104.2".equals(qb.toString())) {
System.out.println("Passed td too high");
} else {
System.out.println("Failed td too high");
System.out.println("Expected: qb td2hi 104.2");
System.out.println("Got: " + qb);
}
// Test td 0
qb.setFirstName("qb");
qb.setLastName("td0");
qb.setAttempts(100);
qb.setCompletions(50);
qb.setYards(1000);
qb.setTouchdowns(0);
qb.setInterceptions(5);
if ("qb td0 64.6".equals(qb.toString())) {
System.out.println("Passed td 0");
} else {
System.out.println("Failed td 0");
System.out.println("Expected: qb td0 64.6");
System.out.println("Got: " + qb);
}
// Test int too low
qb.setFirstName("qb");
qb.setLastName("int2low");
qb.setAttempts(100);
qb.setCompletions(50);
qb.setYards(1000);
qb.setTouchdowns(7);
qb.setInterceptions(11);
if ("qb int2low 69.2".equals(qb.toString())) {
System.out.println("Passed int too low");
} else {
System.out.println("Failed int too low");
System.out.println("Expected: qb int2low 69.2");
System.out.println("Got: " + qb);
}
// Test int 0
qb.setFirstName("qb");
qb.setLastName("int0");
qb.setAttempts(1000);
qb.setCompletions(500);
qb.setYards(10000);
qb.setTouchdowns(70);
qb.setInterceptions(95);
if ("qb int0 69.2".equals(qb.toString())) {
System.out.println("Passed int 0");
} else {
System.out.println("Failed int 0");
System.out.println("Expected: qb int0 69.2");
System.out.println("Got: " + qb);
}
// Test copy and equals
Quarterback qbcopy = new Quarterback();
qbcopy = qb.copy();
if (qbcopy.equals(qb)) {
// copy and equals works
System.out.println("Passed qb copy and equals");
} else {
System.out.println("Failed qb copy and equals");
System.out.println("Original qb: " + qb);
System.out.println("Copied qb: " + qbcopy);
}
}
}
OK. I'll give you some pointers
For the constructor you need to set the objects properties to the relevant arguments passed in the constructor. Then in the copy
method since you already have a constructor that takes all the properties you need to call it with the properties of the current object.
For the equals method you compare primitive types with the ==
operator and strings have an equals method to check for string equality.
To write the toString method you need create a string with the relevant properties and spaces between them and return that string.
That should get you started.
精彩评论