Upload files to "OOP/Java/Lab/Week5"
This commit is contained in:
parent
fe4d8de081
commit
0589cce66a
@ -1,6 +1,7 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
class Book {
|
||||
|
||||
String title, author;
|
||||
int edition;
|
||||
|
||||
@ -11,11 +12,14 @@ class Book {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("Title: %s, Author: %s, Edition: %d", title, author, edition);
|
||||
}
|
||||
return String.format(
|
||||
"Title: %s, Author: %s, Edition: %d",
|
||||
title,
|
||||
author,
|
||||
edition
|
||||
);
|
||||
}
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.print("Enter the number of books: ");
|
||||
@ -41,9 +45,19 @@ class Main {
|
||||
String searchAuthor = sc.nextLine();
|
||||
|
||||
for (Book book : books) {
|
||||
if (book.author.equals(searchAuthor)) {
|
||||
if (book.author.equalsIgnoreCase(searchAuthor)) {
|
||||
System.out.println(book);
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("No books found for the author: " + searchAuthor);
|
||||
|
||||
if (!found) {
|
||||
System.out.println(
|
||||
"No books found for the author: " + searchAuthor
|
||||
);
|
||||
}
|
||||
|
||||
sc.close();
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ class Number {
|
||||
}
|
||||
|
||||
public boolean isEven() {
|
||||
// This is an explicit narrowing typecast from double to int
|
||||
return (int) value % 2 == 0;
|
||||
}
|
||||
|
||||
@ -48,13 +49,22 @@ class Number {
|
||||
System.out.print("Enter a number: ");
|
||||
Number number = new Number(sc.nextDouble());
|
||||
|
||||
System.out.println("Is Zero: " + number.isZero());
|
||||
System.out.println("Is Positive: " + number.isPositive());
|
||||
System.out.println("Is Negative: " + number.isNegative());
|
||||
System.out.println("Is Odd: " + number.isOdd());
|
||||
System.out.println("Is Even: " + number.isEven());
|
||||
System.out.println("Is Prime: " + number.isPrime());
|
||||
System.out.println("Is Armstrong: " + number.isArmstrong());
|
||||
System.out.println(
|
||||
"Is Zero: " +
|
||||
number.isZero() +
|
||||
", Is Positive: " +
|
||||
number.isPositive() +
|
||||
", Is Negative: " +
|
||||
number.isNegative() +
|
||||
", Is Odd: " +
|
||||
number.isOdd() +
|
||||
", Is Even: " +
|
||||
number.isEven() +
|
||||
", Is Prime: " +
|
||||
number.isPrime() +
|
||||
", Is Armstrong: " +
|
||||
number.isArmstrong()
|
||||
);
|
||||
|
||||
sc.close();
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ public class Time {
|
||||
// initializing to zero
|
||||
hr = 0;
|
||||
min = 0;
|
||||
min = 0;
|
||||
sec = 0;
|
||||
}
|
||||
|
||||
Time(int hour, int minute, int second) {
|
||||
|
Loading…
Reference in New Issue
Block a user