Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - package Lab1;
 - public class Dog {
 - private String name;
 - private int age;
 - public Dog(String n, int a){
 - name = n;
 - age = a;
 - }
 - public Dog(String n){
 - name = n;
 - age = 0;
 - }
 - public Dog(){
 - name = "Sam";
 - age = 0;
 - }
 - public void setAge(int age){
 - this.age = age;
 - }
 - public void setName(String name){
 - this.name = name;
 - }
 - public String getName(String name){
 - return name;
 - }
 - public String toString(){
 - return this.name + ", age " + this.age;
 - }
 - public void intoHumanAge(){
 - System.out.println(name+"'s age in human years is " + age * 7 + " years");
 - }
 - }
 - package Lab1;
 - public class TestDog {
 - public static void main(String[] args){
 - Dog d1 = new Dog("Mike", 2);
 - Dog d2 = new Dog("Helen", 7);
 - Dog d3 = new Dog("Bob"); d3.setAge(1);
 - System.out.println(d1);
 - d1.intoHumanAge();
 - d2.intoHumanAge();
 - d3.intoHumanAge();
 - }
 - }
 - package Lab1;
 - public class Ball {
 - private String type;
 - private String color;
 - public Ball(String t, String c){
 - type = t;
 - color = c;
 - }
 - public Ball(String c){
 - type = "Volleyball";
 - color = c;
 - }
 - public Ball(){
 - type = "Football";
 - color = "blue";
 - }
 - public void setColor(String color){
 - this.color = color;
 - }
 - public void setType(String type){
 - this.type = type;
 - }
 - public String toString(){
 - return "The " + this.type + " is " + this.color + " color";
 - }
 - public void showStatus(){
 - System.out.println("The " + type + " is " + color + " color");
 - }
 - }
 - package Lab1;
 - public class TestBall {
 - public static void main(String[] args){
 - Ball b1 = new Ball("Basketball", "Orange");
 - Ball b2 = new Ball("Blue");
 - Ball b3 = new Ball("Rugby", "Yellow");
 - b2.setType("Volleyball");
 - b1.showStatus();
 - b2.showStatus();
 - b3.showStatus();
 - }
 - }
 - package Lab1;
 - public class Book {
 - private String name;
 - private int pages;
 - public Book(String n, int p){
 - name = n;
 - pages = p;
 - }
 - public Book(String n){
 - name = n;
 - pages = 1;
 - }
 - public Book(){
 - name = "Alphabet";
 - pages = 1;
 - }
 - public void setPages(int pages){
 - this.pages = pages;
 - }
 - public void setName(String name){
 - this.name = name;
 - }
 - public String getName(String name){
 - return name;
 - }
 - public String toString(){
 - return "In " + this.name + " " + this.pages + " pages";
 - }
 - public void howManySheets(){
 - System.out.println("In " + name + " " + (pages / 2) + " sheets");
 - }
 - }
 - package Lab1;
 - public class TestBook {
 - public static void main(String[] args) {
 - Book b1 = new Book("Kolobok", 30);
 - Book b2 = new Book("Harry Potter");
 - Book b3 = new Book("Iron Man", 100);
 - b2.setPages(346);
 - System.out.println(b1);
 - b1.howManySheets();
 - b2.howManySheets();
 - b3.howManySheets();
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment