The area of a rectangle is the rectangle’s length times its width. Write a program that asks for the length and width of two rectangles. The program should tell the user which rectangle has the greater area, or if the areas are the same.
String Starts or Ends with given String
Given an array
stringsArray of strings, and startString, endString as inputs, write a JS program to filter the strings in stringsArray starting with startString or ending with endString.
Quick Tip
You can use the array method filter() and logical operator OR ( || ).
Sample Input 1
['teacher', 'friend', 'cricket', 'farmer', 'rose', 'talent', 'trainer']
t
r
Sample Output 1
[ 'teacher', 'farmer', 'talent', 'trainer' ]
Sample Input 2
['dreamer', 'player', 'reader', 'writer', 'trendy']
p
er
Sample Output 2
[ 'dreamer', 'player', 'reader', 'writer' ]
Write four different Java statements that each add 1 to integer variable x.
State whether each of the following is true or false. If false, explain why. a. An algorithm is a procedure for solving a problem in terms of the actions to execute and the order in which these actions execute.
b. A set of statements contained within a pair of parentheses is called a block. c. A selection statement specifies that an action is to be repeated while some condition remains true.
d. A nested control statement appears in the body of another control statement. e. Java provides the arithmetic compound assignment operators +=, -=, *=, /= and %= for abbreviating assignment expressions.
f. The primitive types (boolean, char, byte, short, int, long, float and double) are portable across only Windows platforms.
g. Specifying the order in which statements (actions) execute in a program is called program control.
h. The unary cast operator (double) creates a temporary integer copy of its operand. i. Instance variables of type boolean are given the value TRue by default. j. Pseudocode helps a programmer think out a program before attempting to write it in a programming language.
Given code is :-
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
class Mobile {
constructor(brand, ram, battery, isOnCall, song) {
this.brand = brand;
this.ram = ram;
this.battery = battery;
this.isOnCall = isOnCall;
this.song = song;
this.isOnCall = false;
}
onCall() {
this.isOnCall = true;
}
removeCharging() {
console.log("Please remove charging");
}
charging() {
if (this.battery < 100) {
this.battery = 100;
console.log(`Mobile charged ${this.battery}%`);
} else {
console.log(`Mobile is fully charged`);
this.removeCharging();
}
}
playMusic() {
this.song = this.song;
console.log(`Playing ${this.song} song`);
}
stopMusic() {
this.song = this.song;
console.log('Music stopped');
}
makeCall() {
console.log("Calling...");
}
endCall() {
if (this.isOnCall == false) {
this.isOnCall = true;
console.log('No ongoing call to end');
} else if (this.isOnCall == true) {
console.log('Call Ended');
}
}
}
/* Please do not modify anything below this line */
function main() {
const brand = readLine();
const ram = readLine();
const battery = parseInt(readLine());
const song = readLine();
const isOnCall = JSON.parse(readLine());
const myMobile = new Mobile(brand, ram, battery, isOnCall, song);
console.log(`Mobile charged ${myMobile.battery}%`); // The Mobile battery charged percentage
myMobile.charging(); // The Mobile charging
myMobile.playMusic(); // The Mobile will start playing a song
myMobile.stopMusic(); // The Mobile will stop playing a song
myMobile.endCall(); // The Mobile will end a call.
myMobile.makeCall(); // The Mobile will make a call.
myMobile.endCall(); // The Mobile will end a call.
}
0 <=
battery <= 100
sample input :-
Apple
2 GB
90
Waka Waka
false
sample output :-
Mobile charged 90%
Mobile charged 100%
Playing Waka Waka song
Music stopped
No ongoing call to end
Calling...
Call Ended
Sample Input 2 :-
Samsung
8 GB
100
Gangnam Style
true
Sample Output 2 :-
Mobile charged 100%
Mobile is fully charged
Please remove charging
Playing Gangnam Style song
Music stopped
Call Ended
Calling...
Call Ended
please help me for getting the accurate outputs a above, not error is displaying in the output, but the main problem is in the ( Endcall section) I think so.
Once U please run the code you may understand where to modify.
thankyou.
Square at Alternate Indices
Given an array
Sample Input 1
[ 1, 2, 3, 4, 5 ]
Sample Output 1
[ 1, 2, 9, 4, 25 ]
Sample Input 2
[ 2, 4 ]
Sample Output 2
[ 4, 4 ]
and the given code to fill the function is :
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function main() {
const myArray = JSON.parse(readLine());
/* fill the code in this function */
}
Filter Unique Characters
Given a string
myString as an input, write a JS program to find the unique characters from the myString.
Quick Tip
You can use the array method indexOf().
Sample Input 1
Was it a cat I saw?
Sample Output 1
[
'W', 'a', 's', ' ',
'i', 't', 'c', 'I',
'w', '?'
]
Sample Input 2
I did, did I?
Sample Output 2
[ 'I', ' ', 'd', 'i', ',', '?' ]
String Starts or Ends with given String
Given an array
stringsArray of strings, and startString, endString as inputs, write a JS program to filter the strings in stringsArray starting with startString or ending with endString.
Quick Tip
You can use the array method filter() and logical operator OR ( || ).
Sample Input 1
['teacher', 'friend', 'cricket', 'farmer', 'rose', 'talent', 'trainer']
t
r
Sample Output 1
[ 'teacher', 'farmer', 'talent', 'trainer' ]
Sample Input 2
['dream', 'player', 'read', 'write', 'trend']
p
d
Sample Output 2
[ 'player', 'read', 'trend' ]
String Slicing
Given two strings
Sample Input 1
JavaScript
S
Sample Output 1
Script
Sample Input 2
Language
air
Sample Output 2
Language
Create a class that includes a data member that holds a “serial number” for each
object created from the class. That is, the first object created will be numbered 1, the
second 2, and so on. To do this, you’ll need another data member that records a count
of how many objects have been created so far. (This member should apply to the class
as a whole; not to individual objects. What keyword specifies this?) Then, as each
object is created, its constructor can examine this count member variable to determine
the appropriate serial number for the new object. Add a member function that permits
an object to report its own serial number. Then write a main() program that creates
three objects and queries each one.