B
Bisaflor123
Gast
Hallo Leute hab da eine Kleinigkeit
Also es geht um die System.out.println Ausgabe in der Main-Klasse
Sie gibt immer komische Werte aus
Du hast am edu.hm.cs.swe2.exceptions.datecomponents.Day@9304b1.edu.hm.cs.swe2.exceptions.datecomponents.Month@190d11.edu.hm.cs.swe2.exceptions.datecomponents.Year@a90653Geburtstag
das sollte nich sein, hab schon überlegt in jede klasse methoden zu schreiben und in der main dann die methode aufzuschrufen aber müsste doch auch einfacher gehen oder?
Hat bestimmt was zu tun dass meine Attribute private sind (was sie auch sein sollen) aber die main müsste die doch auch irgendwie lesen können oder?
Hoffe auf antwort :/
Hier die Klassen
Year
Month:
Day
und noch die Main-Klasse
Also es geht um die System.out.println Ausgabe in der Main-Klasse
Sie gibt immer komische Werte aus
Du hast am edu.hm.cs.swe2.exceptions.datecomponents.Day@9304b1.edu.hm.cs.swe2.exceptions.datecomponents.Month@190d11.edu.hm.cs.swe2.exceptions.datecomponents.Year@a90653Geburtstag
das sollte nich sein, hab schon überlegt in jede klasse methoden zu schreiben und in der main dann die methode aufzuschrufen aber müsste doch auch einfacher gehen oder?
Hat bestimmt was zu tun dass meine Attribute private sind (was sie auch sein sollen) aber die main müsste die doch auch irgendwie lesen können oder?
Hoffe auf antwort :/
Hier die Klassen
Year
Java:
package edu.hm.cs.swe2.exceptions.datecomponents;
import java.io.*;
public class Year {
private int year;
public Year (int year)
{
this.year = year;
}
public Year ()
{
}
public void requestBirthYear() throws Exception
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
//int date = Integer.parseInt(input.readLine());
System.out.println("Bitte gib dein Geburtsjahr ein:");
try
{
Integer.parseInt(input.readLine());
}
catch (NumberFormatException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void setYear (int year)
{
this.year = year;
}
public int getYear()
{
return year;
}
}
Month:
Java:
package edu.hm.cs.swe2.exceptions.datecomponents;
import java.io.*;
public class Month {
private int month;
public Month (int month)
{
this.month = month;
}
public Month()
{
}
public void requestBirthMonth() throws Exception
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
//int date = Integer.parseInt(input.readLine());
System.out.println("Bitte gib dein Geburtsmonat ein:");
try
{
Integer.parseInt(input.readLine());
}
catch (NumberFormatException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void setMonth (int month)
{
this.month = month;
}
public int getMonth()
{
return month;
}
}
Day
Java:
package edu.hm.cs.swe2.exceptions.datecomponents;
import java.io.*;
public class Day {
private int day;
public Day (int day)
{
this.day = day;
}
public Day ()
{
}
public void requestBirthDay()
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
//int date = Integer.parseInt(input.readLine());
System.out.println("Bitte gib dein Geburtstag ein:");
try
{
Integer.parseInt(input.readLine());
}
catch (NumberFormatException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void setDay (int day)
{
this.day = day;
}
public int getDay()
{
return day;
}
}
und noch die Main-Klasse
Java:
package edu.hm.cs.swe2.exceptions;
import edu.hm.cs.swe2.exceptions.datecomponents.*;
public class Main {
public static void main(String[] args) throws Exception {
Year year = new Year();
Month month = new Month();
Day day = new Day ();
year.requestBirthYear();
month.requestBirthMonth();
day.requestBirthDay();
System.out.println("Du hast am " + day + "." + month + "." + year + "Geburtstag");
}
}