by CodeChum Admin
Construct a class to represent an air conditioning (AC) unit containing the following attributes:
More details here, Important!
https://pastebin.com/yx0z0Tfr
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a String: ");
String string = in.nextLine().toLowerCase();
System.out.print("Enter character to find: ");
String characterFind = in.nextLine().toLowerCase();
int index = string.indexOf(characterFind);
System.out.print("Index Position: ");
while (index >= 0) {
System.out.print(index + " ");
index = string.indexOf(characterFind, index + 1);
}
in.close();
}
}
Do this coding without using characterFind
Write a program in java.io package to take a String as input then display first word all capital letters, second word all small letters, third word all capital letters and so on.
Example:
Enter a String
Asia is the largest continent
ASIA is THE largest CONTINENT
Don't use array and split function
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a String: ");
String words[] = in.nextLine().toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (i % 2 == 0) {
System.out.print(words[i].toUpperCase() + " ");
} else {
System.out.print(words[i].toLowerCase() + " ");
}
}
in.close();
}
}
Do this programming without using array and split
Write a program to take a name as input then display the signature as the first letter of each word with dot.
Enter a String
Hubert Blaine Wolfeschlegelsteinhausenbergerdorff Sr
H.B.W.S.
Don't use array and split function
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a String: ");
String words[] = in.nextLine().split(" ");
for (int i = 0; i < words.length; i++) {
System.out.print(words[i].toUpperCase().charAt(0) + ".");
}
in.close();
}
}
Do this coding without using array and split
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String names[] = new String[15];
double salaries[] = new double[15];
double salariesTotal = 0;
for (int i = 0; i < names.length; i++) {
System.out.print("Enter employee name " + (i + 1) + ": ");
names[i] = in.nextLine();
System.out.print("Enter employee salary " + (i + 1) + ": ");
salaries[i] = in.nextDouble();
salariesTotal += salaries[i];
in.nextLine();
}
System.out.println();
for (int i = 0; i < names.length; i++) {
System.out.println("Enter employee name: " + names[i]);
System.out.println("Enter employee salary: " + salaries[i]);
}
double averageSalary = salariesTotal / 15.0;
System.out.printf("The average salary employees: %.2f\n", averageSalary);
in.close();
}
}
Do this coding without using array and printf
Write a program to take a String name as input then display the signature using substring().
Example:
Enter a String
Chandra Bahadur Dangi Ailen Coq
C. Bahadur D. Ailen C.
Don't use Array & Split
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a String: ");
String words[] = in.nextLine().split(" ");
for (int i = 0; i < words.length; i++) {
if (i % 2 == 0) {
System.out.print(words[i].substring(0, 1) + ". ");
} else {
System.out.print(words[i] + " ");
}
}
in.close();
}
}
Do this program without using array and split
Write two subclasses of Shape called Circle and Rectangle, as shown in the class diagram.
a) The Circle class contains:
· An instance variable radius (double).
· Three constructors as shown. The no-arg constructor initializes the radius to 1.0.
· Getter and setter for the instance variable radius.
· Methods getArea() and getPerimeter().
· Override the inherited toString() method, to return "A Circle with radius=xxx, which is a subclass of yyy", where yyy is the output of the toString() method from the superclass.
b) The Rectangle class contains:
· Two instance variables width (double) and length (double).
· Three constructors as shown. The no-arg constructor initializes the width and length to 1.0.
· Getter and setter for all the instance variables.
· Methods getArea() and getPerimeter().
· Override the inherited toString() method, to return "A Rectangle with width=xxx and length=zzz, which is a subclass of yyy", where yyy is the output of the toString() method from the superclass.