Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a class Address. An address has a house number, a street, an optional

ID: 3766437 • Letter: I

Question

Implement a class Address. An address has a house number, a street, an optional apartment number, a city, a state, and a postal code. Supply two constructors: one with an apartment number and one without. Supply a print method that prints the address with the street on one line and the city, state, and postal code on the next line. Supply a method public boolean comes before (Address other) that tests whether this address comes before another when the addresses are compared by postal code.

please help me out with this.

Explanation / Answer

import java.io.*;

import java.util.*;

   public class Address {
      
   int h_no;
   String street;
   int ap_no=0;
   String city;
   String state;
   int code;
   Scanner input = new Scanner(System.in);
   Address(int x)
   {
      
       ap_no=x;
          System.out.println("Enter House no")   ;

       h_no=input.nextInt();
       {    System.out.println("Enter Street")   ;

       street=input.next();
       {    System.out.println("Enter City")   ;

       city=input.next();
       System.out.println("Enter State");

       state=input.next();
       System.out.println("Enter Postal Code");

       code=input.nextInt();
      
   }
      
   Address()
   {    System.out.println("Enter House no")   ;

       h_no=input.nextInt();
           System.out.println("Enter Street")   ;

       street=input.next();
       System.out.println("Enter City");
       city=input.next();
       System.out.println("Enter State");
       state=input.next();
       System.out.println("Enter Postal Code");

       code=input.nextInt();  
      
      
   }
   String print()
   {
      
   System.out.println(h_no+" ,"+street)   ;
   System.out.println(city+" ,"+state+" ,"+code)   ;
return h_no+" ,"+street+" ,"+city+" ,"+state+" ,"+code;
      
   }

boolean comesbefore(Address c)
{
   if(this.code<c.code)
   return true;
   else
       return false;
  
}
  
  
       public static void main(String[] args) throws FileNotFoundException {
         
        Address d1=new Address();
        d1.print();
        Address d2=new Address();
        boolean f=d1.comesbefore(d2);
           if(f==true)     
               System.out.println(d1.print()+" comes before")   ;
           else
               System.out.println(d2.print()+" comes before")   ;

        }
  
   }
  
  
  


Please note you did not provide enough information for method "comes Before" like logic to calculate. So I have used logic what feel right. Please provide your logic so I will edit for you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote