Address.java
package testTwo;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class WrongZipCodeException extends Exception{
public WrongZipCodeException(String msg) {
super(msg);
// this will invoke constructor of Exception
class
}
}
public class Address {
private String street, city;
private int number, zip;
public Address() {
street = "";
city = "";
number = 0;
zip = 0;
}
public Address(int number, String city, String street,
int zip) {
this.street = street;
this.city = city;
this.number = number;
try{
if(zip <
1)
throw new WrongZipCodeException("Invalid
zipcode! Zipcode has to be more than 1.");
else
this.zip = zip;
}catch(WrongZipCodeException ex)
{
System.out.println(ex.getMessage());
}
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public int getZip() {
return zip;
}
public void setZip(int zip) {
this.zip = zip;
}
public static void main(String[] args) {
int num, zip;
String street, city;
Address address1 = new
Address(4032, "Debrecen", "Halasz Street", 28);
Address address2 = new
Address(3300, "Hatvan", "Alma street", 6);
Address address3 = new
Address(3700, "Kazincharcika", "Kossuth street", 40);
Scanner in = new
Scanner(System.in); // used to read
input from keyboard
System.out.print("Enter house
number: ");
num = in.nextInt();
in.nextLine();
System.out.print("Enter city:
");
city = in.nextLine();
System.out.print("Enter street
name: ");
street = in.nextLine();
System.out.println("Enter zip code:
");
zip = in.nextInt();
in.nextLine();
Address address4 = new Address(num,
city, street, zip);
// add all address objects to a
list
List<Address> myList = new
ArrayList<>();
myList.add(address1);
myList.add(address2);
myList.add(address3);
myList.add(address4);
// create an object of
SortedAddresses
SortedAddress sorting = new
SortedAddress();
// sort by city names
sorting.sortByCityName(myList);
System.out.println("Sorted by city
name\nZip code \t City");
for(Address a: myList)
{
System.out.println(a.getZip() + "\t\t" + a.getCity());
}
// sort by zip code
sorting.sortByZipCode(myList);
// print sorted address
System.out.println("Sorted by zip
code\nZip code \t City");
for(Address a: myList)
{
System.out.println(a.getZip() + "\t\t" + a.getCity());
}
in.close();
}
}
AddressListHandler.java
package testTwo;
import java.util.List;
public interface AddressListHandler {
public void sortByCityName(List<Address>
l);
public void sortByZipCode(List<Address>
l);
}
SortedAddress.java
package testTwo;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
// this automatically sorts address based on city names
class NameSorting implements Comparator<Address>{
@Override
public int compare(Address a1, Address a2) {
// here is the condition of city
names sorting
return
a1.getCity().compareTo(a2.getCity());
}
}
class ZipSorting implements Comparator<Address>{
@Override
public int compare(Address o1, Address o2) {
return (o1.getZip() -
o2.getZip());
}
}
public class SortedAddress implements AddressListHandler{
public void sortByCityName(List<Address> l)
{
NameSorting ns = new
NameSorting();
Collections.sort(l, ns);
}
public void sortByZipCode(List<Address> l)
{
ZipSorting zs = new
ZipSorting();
Collections.sort(l, zs);
}
}
Output:
![<terminated> Address [Java Application] C:\Program Files\Java\jre\bin\javaw.exe (10-Oct-2019, 9:39:35 pm) Enter house number:](http://img.homeworklib.com/questions/1c6694a0-90ae-11eb-91f1-a9fd2abeaced.png?x-oss-process=image/resize,w_560)
signature 1. Create a new NetBeans Java project. The name of the project has to be...
JAVA LANG PACKAGE Create a NetBeans project for this activity. 1: Create a new class with attributes name and address. Both data type will be String. Create a constructor and assign the parameters to the attributes. Now override the to String() method. 2: Create a class with the main method and create an instance of the class that you created 3: Create an instance of the string in your test class and assign a value. 4: Now create an String...
MasterMind in Java
Activity
MasterMind project
Create a new Java Application project named MasterMind
allowing Netbeans IDE to create the main class called
MasterMind.java
MasterMind class
Method main() should:
Call static method System.out.println() and result in
displaying “Welcome to MasterMind!”
Call static method JOptionPane.showMessageDialog(arg1, arg2)
and result in displaying a message dialog displaying “Let’s Play
MasterMind!”
Instantiate an instance of class Game()
constants
Create package
Constants class
Create class Constants
Create constants by declaring them as “public static final”:
public...
Hi, I need help with this Java activity. The requirements are: 1. Create a NetBeans project for this activity. 2. Create a new class with attributes name and address. Both data type will be String. Create a constructor and assign the parameters to the attributes. 3. Create a class with the main method and create an instance of the class that you created in Test Stem 1. 4. Create an instance of the string in your test class and assign...
In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...
Java Project Create a NetBeans project for this activity. Test Stem / Question Choices 1: Create a new class with attributes name and address. Both data type will be String. Create a constructor and assign the parameters to the attributes. Now override the toString() method. Is this possible? A: Yes. B: No. C: In some cases where the attributes are only strings. D: Yes, as long as you explicitly extends Object class. 2: Create a class with the main method...
Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....
help please
Perform the following steps: a) Using NetBeans, Create a New Java Application Project with Project Name BasePlusCommission Employee Test with Create Main Class check box selected. Create comments to form a descriptive header that has the course name, your name, the assignment title, and a pledge that you have neither received nor provided help to any person. Assignments submitted without this pledge will not be graded. When you have completed the steps (b) and (c) below, you will...
Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML 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 . 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 . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...
// Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...
write in java and please code the four classes with the
requirements instructed
You will be writing a multiclass user management system using the java. Create a program that implements a minimum of four classes. The classes must include: 1. Employee Class with the attributes of Employee ID, First Name, Middle Initial, Last Name, Date of Employment. 2. Employee Type Class that has two instances of EmployeeType objects: salaried and hourly. Each object will have methods that calculates employees payrol...