1 Replies - 278 Views - Last Post: 29 February 2012 - 07:47 PM Rate Topic: -----

#1 emoticons2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-February 12

Issues with get/set methods and constructors. Advice?

Posted 29 February 2012 - 07:42 PM

this is my assignment...


CPSC 155 - COMPUTER PROGRAMMING
SPRING 2012
ASSIGNMENT 6

Date: 02/20/2012
Due On: 02/29/2012

In this project, you’ll be creating a class to hold information about a customer for the tax software we wrote in the last assignment. You won’t need to actually calculate their taxes, or repeat any of that code, this project will just be about creating and using classes to store and retrieve their information.

Create a Customer class that has the following:
1) Fields, all private:
a. name – A String with the first name of the customer
b. income – A double that is the customer’s income
c. married – A char to represent whether the customer is married (‘y’) or not (‘n’).
2) Get Methods: there should be a get method for each of the three fields. Each method returns the value stored in that field.
3) Set Methods:
a. There should not be a set method for the name. After the object is created, it should not be possible to change the customer’s name.
b. There should be a set method for income. This method must check that the new income is valid (0 or above). If it’s not valid, the income should not be changed.
c. There should be a set method for married. This method should check that the new married status is valid (‘n’ or ‘y’). If it’s not valid, the status should not be changed.
4) Constructors: There will be two constructors, one which takes only the user’s name as a parameter, and one which takes all three pieces of information as parameters
a. Constructor with name as the only argument
i. The name should be set to the given value
ii. Income should be set to $10,000.
iii. Married should be set to single (‘n’)
b. Constructor with three parameters
i. The name should be set to the given value
ii. The income should be set to the given value unless it’s not valid. In that case, it should be set to $10,000.
iii. The married status should be set to the given value unless it’s not valid. In that case, it should be set to single (‘n’).
c. The $10,000 default income should be stored in the class as a constant with an appropriate name (the name should explain the purpose of that number, not just the number itself). The constructors should then use the constant, rather than the “magic number.”


(Continued on next page) 
You should also create a second class, Assignment6, with a main function. The main function should do the following, in the given order (note that, unless explicitly stated, the information should be in your code, rather than entered by the user):
1) Create the first customer – Jaden, with an income of $100,000 and who is married.
2) The second customer:
a. Create the second customer – Angela with an income of $60,000, and set to single.
b. Change Angela’s income to $70,000
3) The third customer:
a. Ask the user for the customer’s name
b. Create the customer using the constructor that just takes a name
c. Ask the user for the customer’s income
d. Set the third customer’s income to the user’s input
4) For all three customers, display the name and income on the same line, for example:
Jaden $100,000.0
Angela $70,000.0
Steven $50,000.0
5) Display the name and income of the customer with the lowest income


Submitting the Program
Submit a printout of your program, and a printout of the output your program generates for each of the three given input sequences (Run your program & copy the output screen three times). Use Word to print the output.

Your program must include the following documentation (comments) at the top:
1) Your name
2) The date
3) The assignment number
4) A brief description of what the program does

You must use good variable names, and comment appropriately.

Run the program three times using the following input data:
1) Maria, $60,000
2) Steve, $90,000
3) Sarah, $130,000

this is what i got so far...
---------------------------------------------------------------------------------------------
public class Customer {
private String name;
private double income;
private char married;//char or string?

public String getName ()
{
return name;

}

public double getIncome ()
{
return income;
}

public char getMarried ()
{

return married;

}

public void setIncome (double newIncome){

if (newIncome > 0){
income = newIncome;
}
}

public void setMarried (char newMarried){
if(newMarried != 'y'){
if(newMarried != 'n'){
married = newMarried;
}
}
}

Payer (String payerName, 10000, n)
{
name = payerName;
}

}

//more stuff needs to go here
//more stuff needs to go here
relationshipStatus = newRelationshipStatus;
}

public Customer (String newName) {
name = newName;}
//more stuff needs to go here
//either has to say married or single here. i think or Y or N

//----------------------------------------------------------
//i might not need the above info idk i got confused

public String getname() {
return name;
}
public double getincome() {
return income;
}
public char getrelationshipStatus() {
return relationshipStatus;

}

}
CAN YOU HELP ME FINISH IT? IM SO LOST

Is This A Good Question/Topic? 0
  • +

Replies To: Issues with get/set methods and constructors. Advice?

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1155
  • View blog
  • Posts: 2,536
  • Joined: 05-May 05

Re: Issues with get/set methods and constructors. Advice?

Posted 29 February 2012 - 07:47 PM

Please don't create duplicate threads. Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1