Java program
Candidate Class: This class records the information for each candidate that is running for office.
Instance variables:
Methods:
class Candidate{
String firstname=new String();
String lastname = new String();
String party=new String();
String office = new String();
private int votes=0;
private boolean win=false;
//Constructor for get details
Candidate(String firstname,String
lastname,String office,String party){
this.firstname=firstname;
this.lastname=lastname;
this.office=office;
this.party=party;
}
//Constructor of instance
Candidate(Candidate instance){
firstname=instance.firstname;
lastname=instance.lastname;
office=instance.office;
party=instance.party;
}
//Getters
String getFirstname(){
return firstname;
}
String getLastname(){
return lastname;
}
String getOffice(){
return office;
}
String getParty(){
return party;
}
int getVotes(){
return votes;
}
boolean getWin(){
return win;
}
//Setters
public void setVotes(int value){
votes=value;
}
public void setWin(boolean set){
win=set;
}
public String toString(){//toString Method To
print Candidate details
System.out.println("firstname : "+firstname);
System.out.println("lastname : "+lastname);
System.out.println("office : "+office);
System.out.println("party : "+party);
System.out.println("votes : "+votes);
System.out.println("win
: "+win);
return null;
}
}
public class MainCandidate{
static String equals(Candidate c1,Candidate
c2){
if(c1.firstname==c2.firstname &&
c1.lastname==c2.lastname&& c1.party==c2.party){
return "Equal";
}
return "Not
Equal";
}
public static void main(String
[]args){
Candidate Candidate1 =
new Candidate("Harry","Potter","Newyork","Republic");
Candidate Candidate2 =
new Candidate("Chris","Jordan","Washinton Dc","Congress");
Candidate1.setVotes(1000);
Candidate1.setWin(true);
Candidate2.setVotes(8999);
Candidate2.setWin(false);
System.out.println("Candidate1 firstname :
"+Candidate1.getFirstname());
System.out.println("Candidate1 lastname :
"+Candidate1.getLastname());
System.out.println("Candidate1 office :
"+Candidate1.getOffice());
System.out.println("Candidate1 party :
"+Candidate1.getParty());
System.out.println("Candidate1 votes :
"+Candidate1.getVotes());
System.out.println("Candidate1 win : "+Candidate1.getWin());
System.out.println("Is
Candidate1 equal to Candidate2 :
"+equals(Candidate1,Candidate2));
Candidate Candidate3 =
new Candidate(Candidate1);//passing Candidate1 instance to
Candidate3 which says these are equal values
System.out.println("Is
Candidate1 equal to Candidate3 :
"+equals(Candidate1,Candidate3));
}
}
Output :
Java program Candidate Class: This class records the information for each candidate that is running for...
(2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...
Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...
Write a Python program that creates a class which represents a candidate in an election. The class must have the candidates first and last name, as well as the number of votes received as attributes. The class must also have a method that allows the user to set and get these attributes. Create a separate test module where instances of the class are created, and the methods are tested. Create instances of the class to represent 5 candidates in the...
Java Question 3 Implement a program to store the applicant's information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented as another class to store day, month and year. A variable to store number of years working of type integer...
Utilizing the class diagram above, implement the voting system using JAVA. You will need a main method to allow a voter to register and vote (you need to take in user input). You need to assume getters, setters, constructors, and toString methods; and you need to take in the user input and validate it as well. Comment the code well and submit screenshot testing within your PDF. Hint: you can research regular expressions for the validation functions. VotePersonalldentification voterLastName:String voterFirstName:String...
Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...
Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....
in javaA class called Author is designed as shown in the class diagram. Author name: String email: String gender: char +Author (name :String, email: String, gender char) +getName ():String +getEmail() String +setEmail (email: String) :void +getGender(): char +toString ():String It contains Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f), One constructor to initialize the name, email and gender with the given values; public Author (String name, String email, char gender) f......) public getters/setters: getName(), getEmail setEmail and getGender(); (There are no setters for name and gender,...
Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...
JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...