Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. public class Hund {
  2.         private String name;
  3.         private String breed;
  4.         private int age;
  5.         private double weight;
  6.         private double tail;
  7.         //Ovan står instans variablar
  8.         public static final String TAX = "tax";
  9.        
  10.         public Hund(String name, String breed, int age, double weight) {
  11.                 this.name = name;
  12.                 this.breed = breed;
  13.                 this.age = age;
  14.                 this.weight = weight;
  15.                 this.tail = calculateTail();
  16.         }
  17.         //Nedan är instansmetoder. De har tillgång till instans variablarna
  18.         public String name() {
  19.             return name;
  20.         }
  21.                
  22.         public String breed(){
  23.             return breed;
  24.         }
  25.                
  26.         public void getolder(){
  27.             age++;
  28.         }        //Ökar åldern med ett
  29.        
  30.         public int age(){
  31.             return age;
  32.         }
  33.                
  34.         public void changeWeight(double weight){
  35.                 this.weight = weight; } //Gör så man kan ändra vikt
  36.         public double weight(){return weight;}
  37.                
  38.         public double calculateTail() {
  39.                 if (breed.equalsIgnoreCase("tax")) {
  40.                         return 3.7;
  41.                 }
  42.                 else {
  43.                         return ((age * weight) / 10);
  44.                 }
  45.         }
  46.        
  47.         public double getTail() {
  48.             return tail;
  49.         }
  50.        
  51.  
  52.         public void skrivUt() {
  53.                         System.out.println("Namn: " + name());
  54.                         System.out.println("Ras: " + breed());
  55.                         System.out.println("Ålder: " + age());
  56.                         System.out.println("Vikt: " + weight());
  57.                         System.out.println("Svanslängd: " + tail);
  58.                        
  59.          
  60.                 }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement