Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HAROMSZOG.JAVA
- import javax.swing.JOptionPane;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author hallgato
- */
- public class haromszog {
- private double a, b, c; //adattag
- //private jobb gomb, insert getter, setter
- public void setA(double a) {
- if (0.0 < a && a < this.b + this.c){
- this.a = a;
- }
- else {
- JOptionPane.showMessageDialog(null, "Nem jรณ oldalhossz!", "Hiba", JOptionPane.ERROR_MESSAGE); //grafikus hibauzenet
- //throw new IllegalArgumentException("Hibas oldalhossz!");
- }
- }
- public void setB(double b) {
- this.b = b;
- }
- public void setC(double c) {
- this.c = c;
- }
- public double getA() {
- return a;
- }
- public double getB() {
- return b;
- }
- public double getC() {
- return c;
- }
- public String tostring(){
- return "a=" + a + ", b=" + b + ", c" + c;
- }
- public haromszog(double a, double b, double c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
- }
- TESZT.JAVA
- import java.time.Clock;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author hallgato
- */
- public class Teszt {
- public static void main(String[] args) {
- haromszog h1;
- h1 = new haromszog(3.0, 4.0, 5.0);
- System.out.println(h1.getA());
- System.out.println(h1.getB());
- System.out.println(h1.getC());
- h1.setA(2.0);
- h1.setB(3.0);
- h1.setC(4.0);
- System.out.println(h1.getA());
- System.out.println(h1.getB());
- System.out.println(h1.getC());
- System.out.println(h1); //objektumok string reprezentacioja
- haromszog h2=new haromszog(11.0, 12.0, 13.0);
- h2.setA(22.0);
- h2.setB(23.0);
- h2.setC(24.0);
- System.out.println(h2.getA());
- System.out.println(h2.getB());
- System.out.println(h2.getC());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement