Unit 5 Lesson 2 Coding Activity 1

Unit 5 Lesson 2 Coding Activity 1:

import java.util.Scanner;

public class U5_L2_Activity_One{

public static void

monthName(int x)

{

switch(x)

{

case 1:System.out.println("January");

break;

case 2:System.out.println("February");

break;case 3:System.out.println("March");

break;case 4:System.out.println("April");

break;case 5:System.out.println("May");

break;case 6:System.out.println("June");

break;case 7:System.out.println("July");

break;case 8:System.out.println("August");

break;case 9:System.out.println("September");

break;case 10:System.out.println("October");

break;case 11:System.out.println("November");

break;default:System.out.println("December");

}

}

}

Unit 5 Lesson 2 Coding Activity 2:

import java.util.Scanner;

public class U5_L2_Activity_Two

{

public static void reverser(String x)

{

for(int i=x.length()-1;i>=0;i--)

{

System.out.print(x.charAt(i));

}

}

}

Unit 5 Lesson 2 Coding Activity 3:

import java.util.Scanner;

public class U5_L2_Activity_Three

{

public static void swap(int x,double y)

{

System.out.print(y+" "+x);

}

}

Unit 5 Lesson 2 Coding Activity 4:

import java.util.Scanner;

public class U5_L2_Activity_Four

{

public static void realTime(int x)

{

System.out.printf("Hours: %d\nMinutes: %d\nSeconds: %d",(x/3600),(x/60-(x/3600)*60),(x%60));

}

}

Hope this helps!

public class RightTriangle
{

//field
private double base;
private double height;

public RightTriangle() {
this(1.0,1.0);
}

//Creates a right triangle with base of bs and height of ht if these are positive. If either is not positive, set the length of that side to 1.0.
//constructor
public RightTriangle(double bs, double ht)
{
//set base
if(bs > 0)
{
base = bs;
}
else
{
base = 1;
}

//set height
if(ht > 0)
{
height = ht;
}
else
{
height = 1;
}
}

//methods

public void setBase(double bs)
{
if(bs > 0)
{
base = bs;
}
}

public void setHeight(double ht)
{
if(ht > 0) {
height = ht;
}
}
public double getBase() {
if(base < 0) {
base = 1.0;
return base;
}
else
{
return base;
}
}

public double getHeight() {
if (height < 0) {
height = 1.0;
return height;
}
else
{
return height;
}
}
//find the hypotenuse of right triangle
//*Calculates the length the hypotenuse of the right triangle and returns this as a double.
public double getHypotenuse()
{
return (double)(Math.sqrt(Math.pow(base,2) + Math.pow(height,2)));
}

//Calculates the perimeter of this right triangle as a double.
public double getPerimeter()
{
// hypotenuse = this.getHypotenuse();
return (double)(base + height + getHypotenuse());
}
//Calculates the area of this right triangle as a double.
public double getArea()
{
return (double)((base * height) / 2);
}

//Compares this right triangle to the other. The result is true if and only if the base and height of this right triangle are equal to the base and height respectively of the other right triangle.
public boolean equals(RightTriangle other) {
if(base == other.getBase() && height == other.getHeight()) {
return true;
}
else
{
return false;
}
}

//A String representation of this right triangle. This is in the form "right triangle with base a, height b, hypotenuse c", where a, b and c are the doubles representing the base, height and hypotenuse of the right triangle.
public java.lang.String toString()
{
return "right triangle with base " + base + ", height " + height + ", hypotenuse " + getHypotenuse();
}

}

Follower Tracker

codingMASTER398

A global leader board of the follower counts of Replit users, with growth rates and predictions!

6.2K

156

84

#apps

+4

Blocky Tower

DarekCCC

Target of this game is to stack tetris-like blocks as long as you can. Game ends if one of blocks fall down. No more rules. Game is using KaboomJS with MatterJS. Use spacebar or UP arrow to rotate blocks.

41.2K

292

657

#games

+4

Fendorea

IroncladDev

Share, create, discuss AI-generated images on the stable diffusion engine! Let's make this the most-liked repl ever 😉

4.6K

101

149

#games

+4