Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
Uebung08Wetterstation
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlfaTrainingKurse
Java
Uebung08Wetterstation
Commits
1eed7f02
Commit
1eed7f02
authored
5 years ago
by
Dennis Eisold
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
Branches
master
No related tags found
No related merge requests found
Pipeline
#115
failed with stages
Stage: build
Stage: test
in 19 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Uebung08Wetterstation.iml
+12
-0
12 additions, 0 deletions
Uebung08Wetterstation.iml
src/de/itstall/Main.java
+155
-0
155 additions, 0 deletions
src/de/itstall/Main.java
with
167 additions
and
0 deletions
Uebung08Wetterstation.iml
0 → 100755
+
12
−
0
View file @
1eed7f02
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
This diff is collapsed.
Click to expand it.
src/de/itstall/Main.java
0 → 100755
+
155
−
0
View file @
1eed7f02
package
de.itstall
;
/**
* Output Wetterstation results
*/
public
class
Main
{
/**
* Main method.
* Initialize variables and starts other methods and functions
*
* @param args
*/
public
static
void
main
(
String
[]
args
)
{
/* initialize and fill variables */
int
[][]
iTemperatures
=
new
int
[
2
][];
int
[]
days
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
};
int
[]
daysTemp
=
{
12
,
14
,
9
,
12
,
15
,
16
,
15
,
15
,
11
,
8
,
13
,
13
,
15
,
12
};
iTemperatures
[
0
]
=
days
;
iTemperatures
[
1
]
=
daysTemp
;
/* get average temperature */
double
iAverage
=
tempAverage
(
iTemperatures
);
System
.
out
.
printf
(
"Average temperature: %.2f\n"
,
iAverage
);
/* get min and max temperatures */
int
[]
iMinMaxTemperatures
=
calculateMinMaxTemperature
(
iTemperatures
);
System
.
out
.
println
(
"Max temperature: "
+
iMinMaxTemperatures
[
0
]);
System
.
out
.
println
(
"Min temperature: "
+
iMinMaxTemperatures
[
1
]);
/* calculate turnabout */
calculateTurnabout
(
iTemperatures
);
/* print all days and there temperatures */
printTemperatures
(
iTemperatures
);
}
/**
* calculate the average temperature for given array
* @param temperatures : int[] : temperatures array
* @return averageTemperature : int
*/
private
static
double
tempAverage
(
int
[][]
temperatures
)
{
/* initialize and fill variables */
double
averageTemperature
=
0
;
int
tempAverage
=
0
;
/* loop through the temperatures and get biggest average */
for
(
int
i
=
0
;
i
<
temperatures
[
1
].
length
;
i
++)
{
tempAverage
=
tempAverage
+
temperatures
[
1
][
i
];
}
/* set average temperature */
averageTemperature
=
tempAverage
/
(
double
)
temperatures
[
1
].
length
;
/* return average temperature */
return
averageTemperature
;
}
/**
* calculates the min and max temperatures
* @param temperatures : int[] : temperatures array
* @return iReturn : int[]
*/
private
static
int
[]
calculateMinMaxTemperature
(
int
[][]
temperatures
)
{
/**
* iRetur[0] = max temperature
* iReturn[1] = min temperature
*/
int
[]
iReturn
=
{
0
,
0
};
/* search for min and max temperature */
for
(
int
i
=
0
;
i
<
temperatures
[
1
].
length
;
i
++)
{
/* if current element is bigger than the old max temp */
if
(
temperatures
[
1
][
i
]
>
iReturn
[
0
])
{
iReturn
[
0
]
=
temperatures
[
1
][
i
];
}
else
if
(
i
==
0
)
{
iReturn
[
0
]
=
temperatures
[
1
][
i
];
}
/* if current element is smaller than the old min temp */
if
(
temperatures
[
1
][
i
]
<
iReturn
[
1
])
{
iReturn
[
1
]
=
temperatures
[
1
][
i
];
}
else
if
(
i
==
0
)
{
iReturn
[
1
]
=
temperatures
[
1
][
i
];
}
}
/* return the min and max values */
return
iReturn
;
}
/**
* calculates the biggest temperature turnabout and prints the result to stdout
* @param temperatures : int[] : temperatures array
*/
private
static
void
calculateTurnabout
(
int
[][]
temperatures
)
{
/* initialize and fill variables */
int
maxTempTurnabout
=
0
;
int
dayOfMaxTurnabout
=
0
;
/* loop through all temperatures */
for
(
int
i
=
0
;
i
<
temperatures
[
1
].
length
;
i
++)
{
int
newMaxTurnabout
=
0
;
if
((
i
+
1
)
<
temperatures
[
1
].
length
)
{
/* temperature from next day is bigger than current */
if
(
temperatures
[
1
][
i
]
<
temperatures
[
1
][
i
+
1
])
{
newMaxTurnabout
=
temperatures
[
1
][
i
+
1
]
-
temperatures
[
1
][
i
];
}
/* temperature from next day is smaller or same than current */
if
(
temperatures
[
1
][
i
]
>=
temperatures
[
1
][
i
+
1
])
{
newMaxTurnabout
=
temperatures
[
1
][
i
]
-
temperatures
[
1
][
i
+
1
];
}
/* new max turnabout is bigger that the old one */
if
(
maxTempTurnabout
<
newMaxTurnabout
)
{
maxTempTurnabout
=
newMaxTurnabout
;
dayOfMaxTurnabout
=
i
+
1
;
}
}
}
/* if a turnabout is found, print it to stdout */
if
(
maxTempTurnabout
!=
0
)
{
System
.
out
.
println
(
"Biggest turnabout: "
+
maxTempTurnabout
+
" between days "
+
(
dayOfMaxTurnabout
+
1
)
+
" and "
+
(
dayOfMaxTurnabout
+
2
));
}
else
{
System
.
out
.
println
(
"No temperature diff found."
);
}
}
/**
* prints the temperatures to stdout
* @param temperatures
*/
private
static
void
printTemperatures
(
int
[][]
temperatures
)
{
/* print header to stdout */
System
.
out
.
println
();
System
.
out
.
println
(
"Temperatures per day: "
);
/* print days to stdout */
System
.
out
.
print
(
"Day:\t"
);
for
(
int
i
=
0
;
i
<
temperatures
[
0
].
length
;
i
++)
{
System
.
out
.
print
(
temperatures
[
0
][
i
]
+
"\t"
);
}
System
.
out
.
println
();
/* print temperatures to stdout */
System
.
out
.
print
(
"Temp:\t"
);
for
(
int
i
=
0
;
i
<
temperatures
[
1
].
length
;
i
++)
{
System
.
out
.
printf
(
"%2s\t"
,
temperatures
[
1
][
i
]);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment