by CodeChum Admin
We've been giving positive numbers too much attention lately, it's time to let negative numbers take the spotlight this time!
Instructions:
Instructions
Input
A line containing four decimals/floats separated by a space.
-30.22·10.5·-2.2·-1.8Output
A line containing a negative decimal/floats with two decimal places.
-34.22Write pseudo code that prints the smallest value among a list of numbers.
2. Write a subroutine named "printDayofWeek" that will output the day of the week for a given number. Use Swtich-case. For example, the command "1” would output “Sunday”.
3. The Car class (subclass) inherits the attributes and methods from the Vehicle class (superclass). And every car has model. Please also add toString method to the Car class to print out the brand, and model of the car.
Class Vehicle { protected String brand; Vehicle()
{
Brand = “Ford”; }
public void honk() { System.out.println("Tuut, tuut!");
} }
Please help write the Car class.
4. Try to refactor below codes for computing score (underlined part) with extract methods.
// Vehicle attribute
// Vehicle constructor
// Vehicle method
public class Customer {
void foo() {
int a, b, c, xfactor;
int
}
Write a program that contains a function that displays “Welcome to CS127-8L!” Then, it asks for a double value such as 25.36, 100.02 etc. The maximum is 1000. Getting the double value must be done in a function as called by the main function. Then the main function displays the value in words. Please see the sample runs below.
Run 1 Welcome to CS127-8L! Enter a double value: 225.36 That is two hundred twenty-five and thirty-six centavos!
Run 2 Welcome to CS127-8L! Enter a double value: 800.20 That is eight hundred and twenty centavos!
by CodeChum Admin
I always want to look at the positive side of things, so I decide to seriously look at positive numbers, too!
Will you code along with me?
Instructions:
Instructions
Input
Multiple lines containing an integer on each.
2
3
4
-1
-5
1
0Output
A line containing an integer.
10int a = 5, b = 10, c = 16, d = 0;
What are the outputs after the following Java statements are executed?
(a) if ( d )
else
system.out.println( “true” ); system.out.println( “false” );
(b) if ( a != 5 || b = = 10 ) system.out.println( “true” );
else
system.out.println( “false” );
(c) if ( b <=a && c/d)
system.out.println( “true” );
else
(d) if (a > 5 || d) else
system.out.println( “false” );
system.out.println( “true” ); system.out.println( “false” );
(e) if ( a*d >= d++ )
system.out.println( “true” );
else
system.out.println( “false” );
(f) if (d/a < c*b )
system.out.println( “true” );
else
system.out.println( “false” );
by CodeChum Admin
Can you identify if Cody's name is spelled right? If so, then make a program that accepts four one-letter strings separated by space and print "Correct" if the inputted strings, combined in order, spell the name Cody correctly. If not, print "Wrong". It doesn't matter if it's in uppercase or lowercase, as long as it's spelled correctly, it's considered correct.
Now, will you take on this task?
Input
A line containing four one-letter strings separated by a space.
c·O·D·yOutput
A line containing a string.
Correctby CodeChum Admin
Did you know that you can also reverse lists and group them according to your liking with proper code? Let's try it to believe it.
Instructions:
Input
The first line contains an odd positive integer.
The next lines contains an integer.
5
1
3
4
5
2Output
A line containing a list.
[2,5]-[4]-[3,1]class User :
def __int__(self, user_id, username):
self.id = user_id
self.username = username
user_1 = User("001", "allobang")
print(user_1.username)
user_2 = User("002", "Jack")
print(user_2.username)
ACTIVITIES:
1. Finish this code by adding a password attribute.
2. Assign passwords on user_1 and user_2 of your choice.
3. Create 3rd user object.
a. The value of the id should be your student ID number.
b. The value of username should be your first name.
c. Assign the value of the password attribute of your choice.
4. Print the username of 3rd user object.
class Tool {
private String name = "B tool"; public Tool(String name)
{
this.name = name; }
}
class Hammer extends Tool {
// Suppose Crackable interface exists public void crack(Crackable b)
{
// implementation to crack object b}
}
Will it compile? YES or NO. Give reason, if No.
package studentBase;
class Test
{
String greet = “Hi”;
String name = “Smedley”;
String nickName = name.substring (0,2); If (nickName == name.substring(0,2))
System.out.println(“has real nickname”);
else if (greet + name == greet + nickName);
System.out.println(“no real nickname”);
Else
System.out.println(“hmmm ... changed names?”); }
Will it compile? YES or NO. Give reason, if No.