0% found this document useful (0 votes)
16 views

Politician Class Example

1. Create a Politician class with surname, position, and politicalParty instance variables and corresponding accessor and mutator methods, as well as a constructor to initialize the variables and a goodPolitician method. 2. Create a NetBeans project called PoliticianApp with a main class to test the Politician class. 3. In main(), prompt the user to enter details for two Politician objects, using the default constructor for one and overloaded constructor for the other, and display each politician's details and whether they are a good politician.

Uploaded by

thami dwane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Politician Class Example

1. Create a Politician class with surname, position, and politicalParty instance variables and corresponding accessor and mutator methods, as well as a constructor to initialize the variables and a goodPolitician method. 2. Create a NetBeans project called PoliticianApp with a main class to test the Politician class. 3. In main(), prompt the user to enter details for two Politician objects, using the default constructor for one and overloaded constructor for the other, and display each politician's details and whether they are a good politician.

Uploaded by

thami dwane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Problem 

Description 
1. Create a new NetBeans project called PoliticianApp with a main class. 
2. Create a new Java Class called Politician to the PoliticianApp project and complete it as described below. 
 
The “Politctian” class:   
Complete the Politician class as shown in the UML class diagram and description below: 
 
Politician 
‐ surname: String 
‐ position: String 
‐ politicalParty: String 
+ Politician() 
+ Politician(String, String, String) 
+ setSurname(String): void 
+ setPosition(String): void 
+ setPoliticalParty(String): void 
+ getSurname(): String 
+ getPosition(): String 
+ getPoliticalParty(): String 
+ goodPolitician(int, double): boolean 
 
 
The “Politician” class description: 
 

Member/Method  Description  Marks 


surname  Instance variables of the Politician class.   
position  2 
politicalParty 
Politician()  The default constructor will initialize the instance variables where surname will be “SURNAME”, position will 

be “NOT APPOINTED YET”, and politicalParty will be “MUST MAKE UP YOUR MIND”. 
Politician(String, String, String)  The overloaded constructor will initialize the instance variables to the parameters.  2 
setSurname(String)  Mutator methods   
setPosition(String)  1 
setPoliticalParty(String) 
getSurname()  Accessor methods  1 
getPosition() 
getPoliticalParty() 
goodPolitician(int, double)  This method will receive the budget as an int parameter and the money spend by the politician as the second   
parameter which is of type double. The method should determine the percentage of the money spend of the  6 
budget and then determine of this it is less than 100. 
 
The PoliticianApp Application: 
In the main() method of the PoliticianApp class, complete the following steps: 
 
 Create two instances of the Politician class by allowing the user to enter the required information of each politician and displaying the details of each 
politician including whether he/she is a good politician. 
 For the first object use the default constructor and for the second object use the overloaded parameterized constructor. 
 

You might also like