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