Advertisement
Guest User

bruhh

a guest
Mar 1st, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.64 KB | None | 0 0
  1. public class LegoHat {
  2.     String style;
  3.     int size;
  4.  
  5.     public LegoHat (String s, int t){
  6.       this.style = s;
  7.       this.size = t;
  8.     }
  9.  
  10.     public String toString() {
  11.       return( this.size + " " + this.style );
  12.     }
  13.    
  14.     public int computeStyle(String season, String style){
  15.      
  16.       // 3 styles = toque, cap, or visor
  17.       // two season = summer or winter
  18.      
  19.       int styleScore = 0;
  20.       // toque
  21.       if (season == "summer" && style == "toque") {
  22.         styleScore = 10;
  23.       }
  24.       if (season == "summer" && style == "toque" ){
  25.       styleScore = 1;
  26.       }
  27.      
  28.       // baseball cap
  29.       if (season == "winter" && style == "cap" ){
  30.         styleScore = 3;
  31.       }
  32.       if (season == "summer" && style == "cap" ){
  33.         styleScore = 7;
  34.       }
  35.      
  36.       // sun visor
  37.       if (season == "winter" && style == "visor" ){
  38.         styleScore = 1;
  39.       }
  40.       if (season == "summer" && style == "visor" ){
  41.         styleScore = 10;
  42.       }
  43.       return styleScore;
  44.     }
  45. }
  46.  
  47. public class LegoItem {
  48.   String name;
  49.   float weight;
  50.  
  51.   public LegoItem(String n, float w) {
  52.     this.name = n;
  53.     this.weight = w;
  54.   }
  55.  
  56.   public String toString(){
  57.     return("a " + this.weight + "-gram " + this.name);
  58.   }
  59.  
  60.   public boolean isHeavy(float threshold){
  61.     if (this.weight > threshold){
  62.       return true;
  63.     } else {
  64.       return false;
  65.     }
  66.   }
  67. }
  68.  
  69. public class LegoMinifigure {
  70.   String name;
  71.   LegoHat hat;
  72.   LegoItem itemLeft;
  73.   LegoItem itemRight;
  74.  
  75.   public LegoMinifigure(String n, LegoHat h, LegoItem il, LegoItem ir) {
  76.     this.name = n;
  77.     this.hat = h;
  78.     this.itemLeft = il;
  79.     this.itemRight = ir;
  80.   }
  81.  
  82.   public String toString(){
  83.     return("A lego minifigure name " + this.name + ", who is wearing a size " + hat.toString() + " and is holding " + itemLeft.toString() + " in its left hand and " + itemRight.toString() + " in its right hand.");
  84.   }
  85.  
  86.   public void swapHands() {
  87.     LegoItem temp = itemRight;
  88.     itemRight = itemLeft;
  89.     itemLeft = temp;
  90.   }
  91.  
  92.   public void wearHat(LegoHat hat) {
  93.     this.hat = hat;
  94.   }
  95.  
  96.   public void placeInLeftHand(LegoItem item){
  97.     this.itemLeft = item;
  98.   }
  99.  
  100.   public void placeInRightHand(LegoItem item){
  101.     this.itemRight = item;
  102.   }
  103.  
  104.   public boolean isGood (String season, float threshold){
  105.     boolean reallyIsGood;
  106.     if (hat.computeStyle(season, hat.style) > 6 && itemLeft.isHeavy(threshold) == false && itemRight.isHeavy(threshold) == false){
  107.       reallyIsGood = true;
  108.     } else {
  109.       reallyIsGood = false;
  110.     }
  111.     return reallyIsGood;
  112.   }
  113. }
  114.  
  115. public class TestClass {
  116.   public static void main (String args[]) {
  117.    
  118.     /***************************/
  119.     /*         LegoHat         */
  120.     /***************************/
  121.    
  122.     // creating two hats
  123.     LegoHat hat1 = new LegoHat("toque", 2);
  124.     LegoHat hat2 = new LegoHat("visor", 3);
  125.    
  126.     // to string test
  127.     String test = hat1.toString();
  128.     System.out.println(test);
  129.    
  130.     // computer style test
  131.     int result = hat1.computeStyle("summer", hat1.style);
  132.     System.out.println(result);
  133.    
  134.    
  135.     /***************************/
  136.     /*         LegoItem        */
  137.     /***************************/
  138.    
  139.     // creating four items
  140.     LegoItem item1 = new LegoItem("sword", 10);
  141.     LegoItem item2 = new LegoItem("shield", 15);
  142.     LegoItem item3 = new LegoItem("battle axe", 20);
  143.     LegoItem item4 = new LegoItem("Lance", 7);
  144.    
  145.     // testing toString
  146.     String test2 = item1.toString();
  147.     System.out.println(test2);
  148.    
  149.     // esting isHeavy
  150.     boolean test3 = item1.isHeavy(15);
  151.     System.out.println(test3);
  152.    
  153.     /***************************/
  154.     /*     LegoMinifigure      */
  155.     /***************************/
  156.    
  157.     // creating the minifure
  158.     LegoMinifigure figure1 = new LegoMinifigure("figure1", hat1, item1, item2);
  159.    
  160.     // testing toString
  161.     String test4 = figure1.toString();
  162.     System.out.println(test4);
  163.    
  164.     // testing SwapHands
  165.     figure1.swapHands();
  166.     String test6 = figure1.toString();
  167.     System.out.println(test6);
  168.    
  169.     // testing wearHat
  170.     figure1.wearHat(hat2);
  171.     String test7 = figure1.toString();
  172.     System.out.println(test7);
  173.    
  174.     // testing placeInHand
  175.  
  176.     figure1.placeInLeftHand(item3);
  177.     String test8 = figure1.toString();
  178.     System.out.println(test8);
  179.    
  180.     figure1.placeInRightHand(item4);
  181.     String test9 = figure1.toString();
  182.     System.out.println(test9);
  183.    
  184.     // testing isGood
  185.    
  186.     boolean test10 = figure1.isGood("summer", 15);
  187.     System.out.println(test10);
  188.   }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement