Advertisement
Aminpro

Composite toString

Dec 30th, 2013
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. public class potpie {
  2.     private int month;
  3.     private int day;
  4.     private int year;
  5.    
  6.     public potpie(int m, int d, int y){
  7.         month = m;
  8.         day = d;
  9.         year = y;
  10.        
  11.         System.out.printf("The constructor for this is %s\n", this );
  12.        
  13.     }
  14.    
  15.     public String toString(){
  16.         return String.format("%d/%d/%d", month, day, year);
  17.        
  18.     }
  19. }
  20.  
  21.  
  22. //Class Tuna
  23.  
  24.  
  25. public class Tuna {
  26.     private String name;
  27.     private potpie birthday;
  28.    
  29.     public Tuna(String theName, potpie theDate){
  30.         name = theName;
  31.         birthday = theDate;
  32.        
  33.        
  34.     }
  35.    
  36.     public String toString(){
  37.         return String.format("My name is %s my Bday is %s ", name, birthday);
  38.        
  39.     }
  40.        
  41. }
  42.  
  43.  
  44. //Main Class, apples
  45.  
  46. import java.util.Scanner;
  47.  
  48. class apples{
  49.     public static void main(String args[]){
  50.         potpie potObject = new potpie(14,12,1993);
  51.         Tuna tunaObject = new Tuna("Aminpro", potObject);
  52.    
  53.         System.out.println(tunaObject);
  54.     }
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement