Last active
November 30, 2021 10:38
-
-
Save Rahandi/2d6875ed6c8f09225510b7b5d479436a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Exercie 2.83 | |
*/ | |
public class Book | |
{ | |
// The fields. | |
private String author; | |
private String title; | |
/** | |
* Set the author and title fields when this object | |
* is constructed. | |
*/ | |
public Book(String bookAuthor, String bookTitle) | |
{ | |
author = bookAuthor; | |
title = bookTitle; | |
} | |
public String getAuthor() | |
{ | |
return author; | |
} | |
public String getTitle() | |
{ | |
return title; | |
} | |
} | |
/* | |
Exercise 2.84 | |
*/ | |
public class Book | |
{ | |
// The fields. | |
private String author; | |
private String title; | |
/** | |
* Set the author and title fields when this object | |
* is constructed. | |
*/ | |
public Book(String bookAuthor, String bookTitle) | |
{ | |
author = bookAuthor; | |
title = bookTitle; | |
} | |
public String getAuthor() | |
{ | |
return author; | |
} | |
public String getTitle() | |
{ | |
return title; | |
} | |
public void printAuthor() | |
{ | |
System.out.println(author); | |
} | |
public void printTitle() | |
{ | |
System.out.println(title); | |
} | |
} | |
/* | |
Exercise 2.85 | |
*/ | |
public class Book | |
{ | |
// The fields. | |
private String author; | |
private String title; | |
private int pages; | |
/** | |
* Set the author and title fields when this object | |
* is constructed. | |
*/ | |
public Book(String bookAuthor, String bookTitle, int bookPages) | |
{ | |
author = bookAuthor; | |
title = bookTitle; | |
pages = bookPages; | |
} | |
public String getAuthor() | |
{ | |
return author; | |
} | |
public String getTitle() | |
{ | |
return title; | |
} | |
public void printAuthor() | |
{ | |
System.out.println(author); | |
} | |
public void printTitle() | |
{ | |
System.out.println(title); | |
} | |
public int getPages() | |
{ | |
return pages; | |
} | |
} | |
/* | |
Exercise 2.86 | |
*/ | |
public class Book | |
{ | |
// The fields. | |
private String author; | |
private String title; | |
private int pages; | |
/** | |
* Set the author and title fields when this object | |
* is constructed. | |
*/ | |
public Book(String bookAuthor, String bookTitle, int bookPages) | |
{ | |
author = bookAuthor; | |
title = bookTitle; | |
pages = bookPages; | |
} | |
public String getAuthor() | |
{ | |
return author; | |
} | |
public String getTitle() | |
{ | |
return title; | |
} | |
public void printAuthor() | |
{ | |
System.out.println(author); | |
} | |
public void printTitle() | |
{ | |
System.out.println(title); | |
} | |
public int getPages() | |
{ | |
return pages; | |
} | |
public void printDetails() | |
{ | |
System.out.println("Title :" + title); | |
System.out.println("Author :" + author); | |
System.out.println("Page(s) :" + pages); | |
} | |
} | |
/* | |
Exercise 2.87 | |
*/ | |
import java.util.Scanner; | |
public class Book | |
{ | |
Scanner scan = new Scanner(System.in); | |
// The fields. | |
private String author; | |
private String title; | |
private int pages; | |
private String refNumber; | |
/** | |
* Set the author and title fields when this object | |
* is constructed. | |
*/ | |
public Book(String bookAuthor, String bookTitle, int bookPages) | |
{ | |
author = bookAuthor; | |
title = bookTitle; | |
pages = bookPages; | |
refNumber = ""; | |
} | |
public String getAuthor() | |
{ | |
return author; | |
} | |
public String getTitle() | |
{ | |
return title; | |
} | |
public String getRefNumber() | |
{ | |
return refNumber; | |
} | |
public int getPages() | |
{ | |
return pages; | |
} | |
public void printAuthor() | |
{ | |
System.out.println(author); | |
} | |
public void printTitle() | |
{ | |
System.out.println(title); | |
} | |
public void setRefNumber(String ref) | |
{ | |
refNumber = ref; | |
} | |
public void printDetails() | |
{ | |
System.out.println("Title :" + title); | |
System.out.println("Author :" + author); | |
System.out.println("Page(s) :" + pages); | |
} | |
} | |
/* | |
Exercise 2.88 | |
*/ | |
import java.util.Scanner; | |
public class Book | |
{ | |
Scanner scan = new Scanner(System.in); | |
// The fields. | |
private String author; | |
private String title; | |
private int pages; | |
private String refNumber; | |
/** | |
* Set the author and title fields when this object | |
* is constructed. | |
*/ | |
public Book(String bookAuthor, String bookTitle, int bookPages) | |
{ | |
author = bookAuthor; | |
title = bookTitle; | |
pages = bookPages; | |
refNumber = ""; | |
} | |
public String getAuthor() | |
{ | |
return author; | |
} | |
public String getTitle() | |
{ | |
return title; | |
} | |
public String getRefNumber() | |
{ | |
return refNumber; | |
} | |
public int getPages() | |
{ | |
return pages; | |
} | |
public void printAuthor() | |
{ | |
System.out.println(author); | |
} | |
public void printTitle() | |
{ | |
System.out.println(title); | |
} | |
public void setRefNumber(String ref) | |
{ | |
refNumber = ref; | |
} | |
public void printDetails() | |
{ | |
System.out.println("Title :" + title); | |
System.out.println("Author :" + author); | |
System.out.println("Page(s) :" + pages); | |
if (refNumber.length() != 0) | |
{ | |
System.out.println("Ref. Num :" + refNumber); | |
} | |
else System.out.println("Ref. Num :ZZZ"); | |
} | |
} | |
/* | |
Exercise 2.89 | |
*/ | |
import java.util.Scanner; | |
public class Book | |
{ | |
Scanner scan = new Scanner(System.in); | |
// The fields. | |
private String author; | |
private String title; | |
private int pages; | |
private String refNumber; | |
/** | |
* Set the author and title fields when this object | |
* is constructed. | |
*/ | |
public Book(String bookAuthor, String bookTitle, int bookPages) | |
{ | |
author = bookAuthor; | |
title = bookTitle; | |
pages = bookPages; | |
refNumber = ""; | |
} | |
public String getAuthor() | |
{ | |
return author; | |
} | |
public String getTitle() | |
{ | |
return title; | |
} | |
public String getRefNumber() | |
{ | |
return refNumber; | |
} | |
public int getPages() | |
{ | |
return pages; | |
} | |
public void printAuthor() | |
{ | |
System.out.println(author); | |
} | |
public void printTitle() | |
{ | |
System.out.println(title); | |
} | |
public void setRefNumber(String ref) | |
{ | |
if (ref.length() >= 3) | |
{ | |
refNumber = ref; | |
System.out.println("Set success!"); | |
} | |
else System.out.println("Set failed."); | |
} | |
public void printDetails() | |
{ | |
System.out.println("Title :" + title); | |
System.out.println("Author :" + author); | |
System.out.println("Page(s) :" + pages); | |
if (refNumber.length() != 0) | |
{ | |
System.out.println("Ref. Num :" + refNumber); | |
} | |
else System.out.println("Ref. Num :ZZZ"); | |
} | |
} | |
/* | |
Exercise 2.90 | |
*/ | |
import java.util.Scanner; | |
public class Book | |
{ | |
Scanner scan = new Scanner(System.in); | |
// The fields. | |
private String author; | |
private String title; | |
private int pages; | |
private String refNumber; | |
private int borrowed; | |
private boolean courseText; | |
/** | |
* Set the author and title fields when this object | |
* is constructed. | |
*/ | |
public Book(String bookAuthor, String bookTitle, int bookPages, boolean bookCourseText) | |
{ | |
author = bookAuthor; | |
title = bookTitle; | |
pages = bookPages; | |
refNumber = ""; | |
borrowed = 0; | |
courseText = bookCourseText; | |
} | |
public String getAuthor() | |
{ | |
return author; | |
} | |
public String getTitle() | |
{ | |
return title; | |
} | |
public String getRefNumber() | |
{ | |
return refNumber; | |
} | |
public int getPages() | |
{ | |
return pages; | |
} | |
public int getBorrowed() | |
{ | |
return borrowed; | |
} | |
public boolean isCourseText() | |
{ | |
return courseText; | |
} | |
public void printAuthor() | |
{ | |
System.out.println(author); | |
} | |
public void printTitle() | |
{ | |
System.out.println(title); | |
} | |
public void setRefNumber(String ref) | |
{ | |
if (ref.length() >= 3) | |
{ | |
refNumber = ref; | |
System.out.println("Set success!"); | |
} | |
else System.out.println("Set failed."); | |
} | |
public void borrow() | |
{ | |
borrowed = borrowed + 1; | |
} | |
public void printDetails() | |
{ | |
System.out.println("Title :" + title); | |
System.out.println("Author :" + author); | |
System.out.println("Page(s) :" + pages); | |
if (refNumber.length() != 0) | |
{ | |
System.out.println("Ref. Num :" + refNumber); | |
} | |
else System.out.println("Ref. Num :ZZZ"); | |
System.out.println("Borrowed :" + borrowed); | |
} | |
} | |
/* | |
Exercise 2.91 | |
*/ | |
import java.util.Scanner; | |
public class Book | |
{ | |
Scanner scan = new Scanner(System.in); | |
// The fields. | |
private String author; | |
private String title; | |
private int pages; | |
private String refNumber; | |
private int borrowed; | |
private boolean courseText; | |
/** | |
* Set the author and title fields when this object | |
* is constructed. | |
*/ | |
public Book(String bookAuthor, String bookTitle, int bookPages, boolean bookCourseText) | |
{ | |
author = bookAuthor; | |
title = bookTitle; | |
pages = bookPages; | |
refNumber = ""; | |
borrowed = 0; | |
courseText = bookCourseText; | |
} | |
public String getAuthor() | |
{ | |
return author; | |
} | |
public String getTitle() | |
{ | |
return title; | |
} | |
public String getRefNumber() | |
{ | |
return refNumber; | |
} | |
public int getPages() | |
{ | |
return pages; | |
} | |
public int getBorrowed() | |
{ | |
return borrowed; | |
} | |
public boolean isCourseText() | |
{ | |
return courseText; | |
} | |
public void printAuthor() | |
{ | |
System.out.println(author); | |
} | |
public void printTitle() | |
{ | |
System.out.println(title); | |
} | |
public void setRefNumber(String ref) | |
{ | |
if (ref.length() >= 3) | |
{ | |
refNumber = ref; | |
System.out.println("Set success!"); | |
} | |
else System.out.println("Set failed."); | |
} | |
public void borrow() | |
{ | |
borrowed = borrowed + 1; | |
} | |
public void printDetails() | |
{ | |
System.out.println("Title :" + title); | |
System.out.println("Author :" + author); | |
System.out.println("Page(s) :" + pages); | |
if (refNumber.length() != 0) | |
{ | |
System.out.println("Ref. Num :" + refNumber); | |
} | |
else System.out.println("Ref. Num :ZZZ"); | |
System.out.println("Borrowed :" + borrowed); | |
} | |
} | |
/* | |
Exercise 2.92 | |
*/ | |
public class Heater | |
{ | |
// instance variables - replace the example below with your own | |
private double temperature; | |
/** | |
* Constructor for objects of class Heater | |
*/ | |
public Heater() | |
{ | |
// initialise instance variables | |
temperature = 15.0; | |
} | |
public void warmer() | |
{ | |
temperature = temperature + 5.0; | |
} | |
public void cooler() | |
{ | |
temperature = temperature - 5.0; | |
} | |
public double getTemperature() | |
{ | |
return temperature; | |
} | |
} | |
/* | |
Exercise 2.93 | |
*/ | |
public class Heater | |
{ | |
// instance variables - replace the example below with your own | |
private double temperature; | |
private double min; | |
private double max; | |
private double increment; | |
/** | |
* Constructor for objects of class Heater | |
*/ | |
public Heater(double temperatureMin, double temperatureMax) | |
{ | |
temperature = 15.0; | |
min = temperatureMin; | |
max = temperatureMax; | |
increment = 5.0; | |
} | |
public void warmer() | |
{ | |
if (temperature + increment > max) | |
{ | |
System.out.println("Set failed."); | |
} | |
else | |
{ | |
temperature = temperature + 5.0; | |
System.out.println("Set success!"); | |
} | |
} | |
public void cooler() | |
{ | |
if (temperature + increment < min) | |
{ | |
System.out.println("Set failed."); | |
} | |
else | |
{ | |
temperature = temperature - 5.0; | |
System.out.println("Set success!"); | |
} | |
} | |
public void setIncrement(double inc) | |
{ | |
if (inc < 0) | |
System.out.println("Set failed."); | |
else increment = inc; | |
} | |
public double getTemperature() | |
{ | |
return temperature; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment