Languag JAVA Part 1 13 points Implement a class Address 1 po
Languag: JAVA
Part 1 (13 points)
Implement a class Address. (1 points)
An address has
1. A house number, 2. A street, 3. an optional (positive >0) apartment number, 4. City 5. a state 6. and an (positive >0, 5 digit) integer zip code. Implement these in your class, along with getters and smart setters as shown in class. (6 points)
Supply two constructors: one that configures everything, and one for all but an apartment number. (2 points)
Supply a print method that prints the address with the street on one line, and the city; state; and zip code on the next line. (2 points)
Supply a method public boolean comesBefore(Address other) that tests whether this address comes before another when the addresses are compared by postal code. (2 points)
Part 2 (5 points)
Implement a VotingMachine class that can be used for a simple election. (1 point)
Have methods to
1. Clear the machine state (1 point)
2. To vote for a Democrat (1 point)
3. To vote for a Republican (1 point)
4. To get the tallies for both parties. (1 points)
Part 3 (9 points)
Implement a class Student. (1 point)
For the purpose of this exercise, a student has a name and a total quiz score. Include getters and smart setters, like we did in class. (2 points)
Supply an appropriate (all variables) constructor (1 point)
Implement methods (4 points)
1. getName()
2. addQuiz(int score) . Score must be a positive integer from 0 to 100.
3. getTotalScore()
4. getAverageScore(). To compute the latter, you also need to store the number of quizzes that the student took. (1 point)
Submission
Turn in a .zip of your three .java files to Canvas by your appropriate due date. Ensure you have actually submitted (received confirmation and checked online), since no late labs will be accepted.
Additional Rubric Details
3 points – Comments, Efficiency, File Naming
Additional points can be deducted, however.
Grading will be based on conforming to the standards we reviewed in class as well as following the requirements of this lab.
----------------------------------------------------------------------------------------------------------------------------
Please do all the parts, thank you!
Solution
public class Address {
public Address(int house_number, String street, int apartment_number, String city, String state, int zipcode) {
super();
this.house_number = house_number;
this.street = street;
this.apartment_number = apartment_number;
this.city = city;
this.state = state;
this.zipcode = zipcode;
}
int house_number;
String street;
int apartment_number;
String city,state;
int zipcode;
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public int getHouse_number() {
return house_number;
}
public void setHouse_number(int house_number) {
this.house_number = house_number;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public int getApartment_number() {
return apartment_number;
}
public void setApartment_number(int apartment_number) {
this.apartment_number = apartment_number;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public int getZipcode() {
return zipcode;
}
public void print()
{
System.out.println(street+\"\ \"+city+\"\\t\"+state+\"\\t\"+zipcode);
}
public boolean comesBefore(Address other)
{
if(this.zipcode>other.zipcode)
return true;
return false;
}
public void setZipcode(int zipcode) {
this.zipcode = zipcode;
}
}
=================================================================================
/**
*
*/
/**
* @author akshay
*
*/
public class VotingMachine {
/**
*
*
*/
int Democrat,Republican;
public VotingMachine() {
// TODO Auto-generated constructor stub
Democrat=0;
Republican=0;
}
public void clearState() {
// TODO Auto-generated constructor stub
Democrat=0;
Republican=0;
}
void voteDemocrat()
{
Democrat++;
}
void voteRepublican()
{
Republican++;
}
void Tally()
{
if(Democrat>Republican)
{
System.out.println(\"Democrat win\");
}
else
{
System.out.println(\"Republican win\");
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}



