This question has already been answered:
- Arithmetic operation 2 answers
There is a program with inheritance, consisting of Main, Skelet, Podklass. The program itself is very cumbersome, so I throw part of it.
There are 2 students. Displays an array of their names. Connect the Scanner, enter any of these names. For the selected student both his marks and the average score are displayed. Here only the average score returns the value rounded to an integer. How to make rounding at least to the tenth? I can not understand where the error, even though the rail and a lot.
Skeleton:
public class Skelet { String im; int ocenka1; int ocenka2; double SrBall; public Skelet(String im, int ocenka1, int ocenka2, double srBall) { this.im = im; this.ocenka1 = ocenka1; this.ocenka2 = ocenka2; this.SrBall = srBall; } public String getIm() { return im; } public int getOcenka1() { return ocenka1; } public int getOcenka2() { return ocenka2; } public double getSrBall() { return SrBall = (ocenka1 + ocenka2)/2; } } Subclass:
public class Podklass extends Skelet { public Podklass(String im, int ocenka1, int ocenka2, double SrBall) { super(im, ocenka1, ocenka2, SrBall); } } Main:
import java.util.Scanner; public class Main { public static void main (String[] args) { int i; double sb=0; Podklass uch1 = new Podklass("ΠΠΌΠΈΡΡΠΈΠΉ", 4,3, sb); Podklass uch2 = new Podklass("ΠΠ°ΠΊΡΠΈΠΌ", 5,4, sb); String[] mass = {uch1.getIm(), uch2.getIm()}; for (i=0; i<mass.length; i++){ System.out.println(mass[i]); // ΠΡΠ²ΠΎΠ΄ΠΈΠΌ ΠΌΠ°ΡΡΠΈΠ² ΠΈΠ· ΠΈΠΌΠ΅Π½ } Scanner in = new Scanner(System.in); do { System.out.println(""); System.out.println("ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΠΈΠΌΡ ΡΡΠ΅Π½ΠΈΠΊΠ°: "); String name = in.nextLine(); for (i = 0; i < mass.length; i++) { if (name.equals(mass[0])) { System.out.println(uch1.getIm() + " " + uch1.getOcenka1() + " " + uch1.getOcenka2() + " " + uch1.getSrBall()); break; } if (name.equals(mass[1])) { System.out.println(uch2.getIm() + " " + uch2.getOcenka1() + " " + uch2.getOcenka2() + " " + uch2.getSrBall()); break; } else { break; } } } while (mass.length==2); } }