Skip to content
Snippets Groups Projects
Commit afd29aa0 authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

live06

parent 66275269
No related branches found
No related tags found
No related merge requests found
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/modules.xml
/.idea.live06.iml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
using System;
using System.Text;
/// @author Omanimi
/// @version 19.09.2023
/// <summary>
///
/// </summary>
public class Laskuja
{
/// <summary>
///
/// </summary>
public static void Main()
{
int a = 3;
int b = 2;
double ka = Keskiarvo(a, b);
Console.WriteLine(ka);
int ero = Vahenna(a, 9);
Console.WriteLine(ero);
char k = 'a';
const bool tuleekoIsona = false;
string jono = Monista(k, 5, tuleekoIsona);
Console.WriteLine(jono);
}
/// <summary>
///
/// </summary>
/// <param name="k"></param>
/// <param name="montako"></param>
/// <param name="isona">true jos isona, muuten false</param>
/// <returns>kirjain monistettuna</returns>
/// <example>
/// <pre name="test">
/// Monista('a', 3, false) === "aaa";
/// Monista('b', 3, true) === "BBB";
/// Monista('b', 0, true) === "";
/// </pre>
/// </example>
public static string Monista(char k ,int montako , bool isona)
{
StringBuilder tulos = new StringBuilder();
char kirjain = char.ToLower(k);
if (isona) kirjain = char.ToUpper(k);
for (int i = 0; i < montako; i++)
{
tulos.Append(kirjain);
}
return tulos.ToString();
}
/// <summary>
/// Lasketana lukujen erotus
/// </summary>
/// <param name="a">luku josta vähennetään</param>
/// <param name="b">luku joka vähennetään</param>
/// <returns>a-b</returns>
/// <example>
/// <pre name="test">
/// Vahenna(2, 2) === 0;
/// Vahenna(5, 3) === 2;
/// Vahenna(3, 7) === -4;
/// </pre>
/// </example>
public static int Vahenna(int a, int b)
{
int tulos = a - b;
return tulos;
}
/// <summary>
/// Lasketaan kahden luvun keskiarvo
/// </summary>
/// <param name="a">eka luku</param>
/// <param name="b">toka luku</param>
/// <returns>lukujen keskiarvo</returns>
/// <example>
/// <pre name="test">
/// Keskiarvo(0,0) ~~~ 0;
/// Keskiarvo(2,3) ~~~ 2.5;
/// Keskiarvo(-2,3) ~~~ 0.5;
/// </pre>
/// </example>
public static double Keskiarvo(int a, int b)
{
int summa = a + b;
double tulos = summa / 2.0;
return tulos;
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
</Project>
using System;
using System.Text;
using NUnit.Framework;
using static Laskuja;
[TestFixture]
[DefaultFloatingPointTolerance(0.000001)]
public class TestLaskuja
{
[Test]
public void TestMonista40()
{
Assert.AreEqual( "aaa", Monista('a', 3, false) , "in method Monista, line 41");
Assert.AreEqual( "BBB", Monista('b', 3, true) , "in method Monista, line 42");
Assert.AreEqual( "", Monista('b', 0, true) , "in method Monista, line 43");
}
[Test]
public void TestVahenna66()
{
Assert.AreEqual( 0, Vahenna(2, 2) , "in method Vahenna, line 67");
Assert.AreEqual( 2, Vahenna(5, 3) , "in method Vahenna, line 68");
Assert.AreEqual( -4, Vahenna(3, 7) , "in method Vahenna, line 69");
}
[Test]
public void TestKeskiarvo86()
{
Assert.AreEqual( 0, Keskiarvo(0,0) , 0.000001, "in method Keskiarvo, line 87");
Assert.AreEqual( 2.5, Keskiarvo(2,3) , 0.000001, "in method Keskiarvo, line 88");
Assert.AreEqual( 0, Keskiarvo(-2,3) , 0.000001, "in method Keskiarvo, line 89");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.1"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Laskuja\Laskuja.csproj"/>
</ItemGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Laskuja", "Laskuja\Laskuja.csproj", "{C40B6089-C810-42D4-88A2-0BC16C813A2A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaskujaTest", "LaskujaTest\LaskujaTest.csproj", "{04FA345B-3256-4B6C-847C-9AEA89F9B9B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C40B6089-C810-42D4-88A2-0BC16C813A2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C40B6089-C810-42D4-88A2-0BC16C813A2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C40B6089-C810-42D4-88A2-0BC16C813A2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C40B6089-C810-42D4-88A2-0BC16C813A2A}.Release|Any CPU.Build.0 = Release|Any CPU
{04FA345B-3256-4B6C-847C-9AEA89F9B9B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04FA345B-3256-4B6C-847C-9AEA89F9B9B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04FA345B-3256-4B6C-847C-9AEA89F9B9B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04FA345B-3256-4B6C-847C-9AEA89F9B9B5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Laskuja", "Laskuja\Laskuja.csproj", "{C40B6089-C810-42D4-88A2-0BC16C813A2A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C40B6089-C810-42D4-88A2-0BC16C813A2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C40B6089-C810-42D4-88A2-0BC16C813A2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C40B6089-C810-42D4-88A2-0BC16C813A2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C40B6089-C810-42D4-88A2-0BC16C813A2A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
......@@ -4,7 +4,7 @@ namespace LumiukkoVoima;
/// @author Vesa Lappalainen
/// @version 19.9.2023
///
///
/// <summary>
/// Neljä lumiukkoa aliohjelman avulla, funktio palauttaa taulukon palloja
/// </summary>
......@@ -61,14 +61,13 @@ public class LumiukkoVoima : PhysicsGame
/// <returns>taulukko ukon palloista</returns>
public static PhysicsObject[] PiirraLumiukko(PhysicsGame peli, double x, double y, double r=100)
{
PhysicsObject p1, p2, p3;
double r1 = r;
double r2 = r1 * 0.5;
double r3 = r1 * 0.3;
p1 = PiirraPallo(peli, x, y, r1);
p2 = PiirraPallo(peli, x, p1.Y + r1 + r2, r2);
p3 = PiirraPallo(peli, x, p2.Y + r2 + r3, r3);
PhysicsObject p1 = PiirraPallo(peli, x, y, r1);
PhysicsObject p2 = PiirraPallo(peli, x, p1.Y + r1 + r2, r2);
PhysicsObject p3 = PiirraPallo(peli, x, p2.Y + r2 + r3, r3);
return new PhysicsObject[] { p1, p2, p3 };
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment