-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 489f81c
Showing
4 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package oppgave1; | ||
|
||
|
||
|
||
|
||
public class Resultat | ||
{ | ||
public static void main(String [] args) | ||
{ | ||
|
||
|
||
Student student1 = new Student ("Mia"); | ||
Student student2 = new Student ("Fredrik"); | ||
|
||
|
||
student1.resultatInn(); | ||
System.out.println(student1.toString() + "\n"); | ||
|
||
student2.resultatInn(); | ||
System.out.println(student2.toString() + "\n"); | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package oppgave1; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Student | ||
{ | ||
|
||
|
||
public String navn; | ||
public int snitt; | ||
public int test1, test2, test3; | ||
|
||
|
||
|
||
public Student(String studentnavn) | ||
{ | ||
navn = studentnavn; | ||
|
||
} | ||
|
||
public void resultatInn() | ||
{ | ||
|
||
|
||
Scanner scan = new Scanner (System.in); | ||
|
||
System.out.println("Skriv inn " + navn + "s resultat for test 1:"); | ||
test1 = scan.nextInt(); | ||
System.out.println("Skriv inn " + navn + "s resultat for test 2:"); | ||
test2 = scan.nextInt(); | ||
System.out.println("Skriv inn " + navn + "s resultat for test 3:"); | ||
test3 = scan.nextInt(); | ||
|
||
} | ||
|
||
|
||
public int finnSnitt() | ||
{ | ||
|
||
return ((test1 + test2 + test3)/3); | ||
|
||
} | ||
|
||
|
||
public String finnNavn() | ||
{ | ||
|
||
return navn; | ||
|
||
|
||
} | ||
|
||
public String toString() | ||
{ | ||
|
||
return "\nNavn: " + navn + "\tTest 1:\t" + test1 + "\tTest 2:\t" + test2 + "\tTest 3:\t" + test3 + "\tSnitt: " + finnSnitt(); | ||
|
||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package oppgave2; | ||
import java.text.DecimalFormat; | ||
import java.util.Scanner; | ||
|
||
|
||
public class Vare { | ||
|
||
private String vNavn , vEnhet; | ||
private double vPris; | ||
private int vAntall; | ||
|
||
public Vare(String varenavn, String vareenhet, double varepris, int vareantall) | ||
{ | ||
vNavn = varenavn; | ||
vEnhet = vareenhet; | ||
vPris = varepris; | ||
vAntall = vareantall; | ||
} | ||
|
||
// hent navn | ||
public String hentvNavn() | ||
{ | ||
return vNavn; | ||
} | ||
|
||
// hent enhet | ||
public String hentvEnhet() | ||
{ | ||
return vEnhet; | ||
} | ||
|
||
// hent pris | ||
public Double hentvpris() | ||
{ | ||
return vPris; | ||
} | ||
|
||
// hent Antall | ||
public double hentvAntall() | ||
{ | ||
return vAntall; | ||
} | ||
|
||
// oppgradere navn | ||
public void settNavn(String nyttNavn) | ||
{ | ||
vNavn = nyttNavn; | ||
} | ||
|
||
// oppgradere enhet | ||
public void settEnhet(String nyEnhet) | ||
{ | ||
vEnhet = nyEnhet; | ||
} | ||
|
||
// oppgradere pris | ||
public void settPris(double nyPris) | ||
{ | ||
vPris = nyPris; | ||
} | ||
|
||
// oppgradere antall | ||
public void settAntall(int nyAntall) | ||
{ | ||
vAntall = nyAntall; | ||
} | ||
|
||
public void vareInn() | ||
{ | ||
// S¿keren for tastetrykk | ||
Scanner scan = new Scanner (System.in); | ||
String pynt = "________________________\n"; | ||
|
||
// Sp¿ring | ||
System.out.println("\nHva heter den nye varen?"); | ||
vNavn = scan.nextLine(); | ||
System.out.println("Hvordan enhet har " + vNavn + "?"); | ||
vEnhet = scan.nextLine(); | ||
System.out.println("Hvor mange " + vEnhet + " skal du ha?"); | ||
vAntall = scan.nextInt(); | ||
System.out.println("Pris per " + vEnhet + " (eks 2.90)?"); | ||
vPris = scan.nextDouble(); | ||
System.out.println("\n"+ pynt +"-- Vare " + vNavn + " lagt til --\n" + pynt); | ||
|
||
} | ||
|
||
// toString utskriften | ||
public String toString() | ||
{ | ||
// runde av til 2 desimaler | ||
DecimalFormat valuta = new DecimalFormat("#0.00"); | ||
|
||
// legger sammen pris og antall | ||
double leggsammen = (vPris*vAntall); | ||
|
||
// print ut resultatet | ||
String resultat = "\t" + vNavn + "\t\t x " + vAntall + "\t\tper " + vEnhet + "\t\t" + valuta.format(vPris) +",-" + "\n\t\t\t\t\t\t\t\t\t" + valuta.format(leggsammen) ; | ||
return resultat; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package oppgave2; | ||
import java.text.DecimalFormat; | ||
|
||
|
||
public class VareRegister { | ||
|
||
|
||
public static void main(String[] args) | ||
{ | ||
|
||
// runde av til 2 desimaler | ||
DecimalFormat valuta = new DecimalFormat("#0.00"); | ||
|
||
// varer | ||
Vare vare1, vare2, vare3; | ||
vare1 = new Vare("Melk", "L" ,8.90,3); | ||
vare2 = new Vare("Egg","stk",1.50,6); | ||
vare3 = new Vare("Bacon","kg",59.0,1); | ||
|
||
// legge sammen totalsummen | ||
double vare1sum = (vare1.hentvpris()*vare1.hentvAntall()); | ||
double vare2sum = (vare2.hentvpris()*vare2.hentvAntall()); | ||
double vare3sum = (vare3.hentvpris()*vare3.hentvAntall()); | ||
double total = (vare1sum + vare2sum + vare3sum); | ||
|
||
// Pynt til utskrift i console | ||
String info = "\tProdukt\t\tAntall\t\tEnhet\t\tPris\t\tSum"; | ||
String header = " \t\t Rema 1000 \n"; | ||
String pynt = "_____________________________________________________________________________________"; | ||
String topp = pynt + "\n" + header + pynt + "\n" + info + "\n" + pynt + "\n" ; | ||
|
||
// Printer varene ut til console | ||
System.out.println(topp); | ||
System.out.println(vare1); | ||
System.out.println(vare2); | ||
System.out.println(vare3); | ||
System.out.println(pynt); | ||
System.out.println("\t\t\t\t\t\t\t\tTotal:\t" + valuta.format(total) + ",-"); | ||
System.out.println(pynt); | ||
|
||
|
||
// Leser inn 3 nye vareverdier | ||
vare1.vareInn(); | ||
vare2.vareInn(); | ||
vare3.vareInn(); | ||
|
||
// Regner totalsummen summen av 3 nye varer | ||
vare1sum = (vare1.hentvpris()*vare1.hentvAntall()); | ||
vare2sum = (vare2.hentvpris()*vare2.hentvAntall()); | ||
vare3sum = (vare3.hentvpris()*vare3.hentvAntall()); | ||
total = (vare1sum + vare2sum + vare3sum); | ||
|
||
// Printer toString ut til console | ||
System.out.println(topp); | ||
System.out.println(vare1.toString()); | ||
System.out.println(vare2.toString()); | ||
System.out.println(vare3.toString()); | ||
System.out.println(pynt); | ||
System.out.println("\t\t\t\t\t\t\t\tTotal:\t" + valuta.format(total) + ",-"); | ||
System.out.println(pynt); | ||
|
||
} | ||
} | ||
|