Advertisement
apez1

Assignment 2: Part 1 - Boxcar

Jan 13th, 2019
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package boxcar;
  2.  
  3. public class Boxcar {
  4.  
  5.     // Variables that will be initialized in the Boxcar constructors.
  6.     private String cargo = "";
  7.     private int numUnits;
  8.     private boolean repair;
  9.  
  10.     // Default constructor that sets the boxcar to "gizmos", 5, and false.
  11.     public Boxcar()
  12.     {      
  13.         cargo = "gizmos" ;
  14.         numUnits = 5 ;
  15.         repair = false ;
  16.            
  17.     }
  18.  
  19.  
  20.     public Boxcar(String c, int u, boolean r)
  21.     {
  22.  
  23.         if(c.toLowerCase().equals("gizmos")|| c.toLowerCase().equals("gadgets") || c.toLowerCase().equals("widgets") || c.toLowerCase().equals("wadgets")) {   
  24.             cargo = c ;
  25.         }
  26.         else {
  27.             cargo = "gizmos" ;
  28.            
  29.         }
  30.    
  31.         numUnits = u;
  32.        
  33.         if(numUnits < 0 || numUnits > 10) {
  34.             numUnits = 0 ;
  35.         }
  36.        
  37.         repair = r ;
  38.        
  39.         if(repair == true) {
  40.            
  41.             numUnits = 0 ;
  42.         }
  43.        
  44.    
  45.     }
  46.    
  47.  
  48.     public String toString()
  49.     {
  50.        
  51.         String output = null ;
  52.         String output1 = null;
  53.            
  54.             if(repair == true) {
  55.                 output1 = "in repair" ;
  56.                
  57.             }
  58.             else {
  59.                 output1 = "in service" ;
  60.             }
  61.        
  62.        
  63.        
  64.          output =  numUnits + " " + cargo.toLowerCase() + "\t" + output1 ;
  65.        
  66.        
  67.         return output;
  68.     }
  69.  
  70.    
  71.  
  72.     public void loadCargo() {
  73.        
  74.         numUnits ++ ;
  75.         if(numUnits > 10) {
  76.             numUnits = 10 ;
  77.         }
  78.        
  79.         if(repair == true) {
  80.             numUnits = 0 ;
  81.         }
  82.        
  83.     }
  84.  
  85.    
  86.     public String getCargo()
  87.     {  
  88.         return cargo;
  89.     }
  90.  
  91.    
  92.     public void setCargo(String c)
  93.     {
  94.  
  95.         if(c.equalsIgnoreCase("gizmos") || c.equalsIgnoreCase("gadgets") || c.equalsIgnoreCase("widgets") || c.equalsIgnoreCase("wadgets") ) {
  96.            
  97.             cargo = c.toLowerCase() ;
  98.            
  99.         }
  100.         else {
  101.             cargo = "gizmos" ;
  102.         }
  103.    
  104.    
  105.    
  106.    
  107.    
  108.     }
  109.  
  110.  
  111.    
  112.     public boolean isFull()
  113.     {
  114.  
  115.         boolean output1 ;
  116.        
  117.         if(numUnits == 10) {
  118.             output1 = true ;
  119.         }
  120.         else {
  121.             output1 = false ;
  122.         }
  123.  
  124.         return output1;
  125.     }
  126.  
  127.  
  128.     public void callForRepair()
  129.     {
  130.        
  131.         repair = true;
  132.         if(repair == true) {
  133.             numUnits = 0 ;
  134.         }
  135.        
  136.    
  137.     }
  138.    
  139.    
  140.    
  141.    
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement