Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ø
Øving 5
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Programmering 1 Øvinger
Øving 5
Commits
1e714965
Commit
1e714965
authored
7 months ago
by
Benjamin Kvello-Hansen
Browse files
Options
Downloads
Patches
Plain Diff
Update 2 files
- /oppgave1.java - /oppgave2.java
parent
ca61ea9c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
oppgave1.java
+67
-0
67 additions, 0 deletions
oppgave1.java
oppgave2.java
+29
-0
29 additions, 0 deletions
oppgave2.java
with
96 additions
and
0 deletions
oppgave1.java
0 → 100644
+
67
−
0
View file @
1e714965
class
Brok
{
private
int
nevner
;
private
int
teller
;
public
Brok
(
int
teller
,
int
nevner
)
{
if
(
nevner
==
0
)
{
throw
new
IllegalArgumentException
(
"Nevner kan ikke være 0"
);
}
this
.
teller
=
teller
;
this
.
nevner
=
nevner
;
}
public
Brok
(
int
teller
)
{
this
(
teller
,
1
);
}
public
void
addisjon
(
Brok
other
)
{
this
.
teller
=
this
.
teller
*
other
.
nevner
+
other
.
teller
*
this
.
nevner
;
this
.
nevner
=
this
.
nevner
*
other
.
nevner
;
}
public
void
subtraksjon
(
Brok
other
)
{
this
.
teller
=
this
.
teller
*
other
.
nevner
-
other
.
teller
*
this
.
nevner
;
this
.
nevner
=
this
.
nevner
*
other
.
nevner
;
}
public
void
multiplikasjon
(
Brok
other
)
{
this
.
teller
=
this
.
teller
*
other
.
teller
;
this
.
nevner
=
this
.
nevner
*
other
.
nevner
;
}
public
void
deling
(
Brok
other
)
{
this
.
teller
=
this
.
teller
*
other
.
nevner
;
this
.
nevner
=
this
.
nevner
*
other
.
teller
;
}
public
int
getTeller
()
{
return
this
.
teller
;
}
public
int
getNevner
()
{
return
this
.
nevner
;
}
public
static
void
main
(
String
[]
args
)
{
Brok
A
=
new
Brok
(
1
,
2
);
Brok
B
=
new
Brok
(
2
,
3
);
Brok
C
=
new
Brok
(
10
);
A
.
addisjon
(
B
);
System
.
out
.
println
(
"Etter addisjon: "
+
A
.
getTeller
()
+
"/"
+
A
.
getNevner
());
A
=
new
Brok
(
1
,
2
);
A
.
subtraksjon
(
B
);
System
.
out
.
println
(
"Etter subtraksjon: "
+
A
.
getTeller
()
+
"/"
+
A
.
getNevner
());
A
=
new
Brok
(
1
,
2
);
A
.
multiplikasjon
(
B
);
System
.
out
.
println
(
"Etter multiplikasjon: "
+
A
.
getTeller
()
+
"/"
+
A
.
getNevner
());
A
=
new
Brok
(
1
,
2
);
A
.
deling
(
B
);
System
.
out
.
println
(
"Etter deling: "
+
A
.
getTeller
()
+
"/"
+
A
.
getNevner
());
System
.
out
.
println
(
C
.
teller
+
"/"
+
C
.
nevner
);
}
}
This diff is collapsed.
Click to expand it.
oppgave2.java
0 → 100644
+
29
−
0
View file @
1e714965
import
java.util.Random
;
class
MinRandom
{
private
Random
random
=
new
Random
();
public
int
nesteHeltall
(
int
nedre
,
int
ovre
)
{
return
random
.
nextInt
(
ovre
-
nedre
-
1
)
+
nedre
+
1
;
}
public
double
nesteDesimaltall
(
double
nedre
,
double
ovre
)
{
return
nedre
+
(
ovre
-
nedre
)
*
random
.
nextDouble
();
}
public
static
void
main
(
String
[]
args
)
{
MinRandom
minRandom
=
new
MinRandom
();
System
.
out
.
println
(
"Tilfeldige heltall mellom 1 og 6 (ikke inkludert 1 og 6):"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
int
heltall
=
minRandom
.
nesteHeltall
(
1
,
6
);
System
.
out
.
print
(
heltall
+
" "
);
}
System
.
out
.
println
(
"\nTilfeldige desimaltall mellom 1.0 og 6.0 (inkludert 1.0, ikke inkludert 6.0):"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
double
desimaltall
=
minRandom
.
nesteDesimaltall
(
1.0
,
6.0
);
System
.
out
.
print
(
desimaltall
+
" "
);
}
}
}
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