Results 1 to 13 of 13
  1. #1
    Aname is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Exclamation Stuck with my inheritance java testing :'(

    [edited my question to make it more clear]
    hi guys, i think i got a couple of stupid rookie mistakes in my program, im a noobie, but if you correct it, could you please tell me why you put it like that.
    thank you. :)
    there are no errors except that
    I would like to make with my main class where i can ask like a prompt box popped up, how much credits a student wants from the student class, and not something like this
    Java Code:
     someStudent.setCredits(1000);

    For example in my main Instead of using
    Java Code:
    someStudent.setCredits(1000); 
    System.out.println(someStudent.getCredits());
    i would like to make something like this:

    Java Code:
    Student SomeStudent;
    SimpleInOutDialog InOut;
    		
    		double double credits;
    		
    		InOut = new SimpleInOutDialog("somethingSomething");
    		
    		credits = InOut.readDouble("tell me how much credits you need");
                    SomeStudent = new Student ("Mister Jones");
    		creditAnswer = SomeStudent.getCredits();
    		InOut.showDouble("your credits are  ", creditAnswer);
    Class person:

    Java Code:
     
    package testing;
    
    public class Person {
    
    	private  String name;
    
    	
    	// dit wordt een constructor en hiermee kunnen we in de variabele zetten (P)
    	public Person (String name){
    		this.name = name;
    	}
    	
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    // toString moet gebruikt worden bij het maken van een string
    	public String toString(){
    	return name;
    }
    	static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    	}
    
    }
    i use class student to inherit from class person but heres the problem and also my main class...
    package testing;
    Java Code:
    package testing;
    
    public class Student extends Person {
    	
    	private double credits;
    
    	public Student(String name ) {
    		super(name);
    		
    		
    		// TODO Auto-generated constructor stub
    	}
    	
    
    	public double getCredits() {
    		return credits;
    	}
    
    	public void setCredits(double credits) {
    		this.credits = credits;
    	}
    	
    	public String toString(){
    		return getName() + " has: " + credits + " Credits ";
    		
    	}
    	
    }
    And employee also inherit from the class person
    Java Code:
    package testing;
    
    public class Employee extends Person {
    	
    	public Employee(String name) {
    		super(name);
    		// TODO Auto-generated constructor stub
    	}
    
    	private double salary;
    
    	public double getSalary() {
    		return salary;
    	}
    
    	public void setSalary(double salary) {
    		this.salary = salary;
    	}
    
    }
    And finnaly my main class
    Java Code:
    package testing;
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    	
    		
    		SimpleInOutDialog InOut;
    		InOut = new SimpleInOutDialog("something");
    		
    		Person P = new Person("willy");
    		System.out.println(P);
    		Person A = new Person("");
    		A.setName("wilson");
    		System.out.println(A);
    		
    		Student harry = new Student ("harry potter");
    		Student Ron = new Student ("Ron");
    	
    		
    		
    		
    		Student hermelien = new Student ("hermelientje potter");
    		
    		
    		Employee marian = new Employee("mariannetje");
    		// marian.setSalary(1000);
    		System.out.println(marian.getSalary());
    		System.out.println(harry);
    		System.out.println(Ron);
    		System.out.println(hermelien);
    		
    	}
    }
    And finnaly i use this little java script to read doubles, integers, strings etc...
    its quite easy .. well normally xD

    but this script has certainly no mistakes in it, it just helps to read stuff easier like for example
    credits= InOut.readDouble("how much credits?");
    Student hermelien = new Student ("hermelientje potter");
    creditAnswer = hermelien.getcredits();
    InOut.showDouble("your credits are ", creditAnswer);

    something like that
    Java Code:
    package testing;
    import javax.swing.JOptionPane;
    
    /**
     * @author Jan Beurghs<br>
     * 17-mei-2004<br>
     *
     */
    public class SimpleInOutDialog {
    
    	private String titel;
    
    	/**
    	 * Constructor van een SimpleInOutDialog.
    	 *
    	 * @param titel een String met de titel van het venstertje.
    	 */
    	public SimpleInOutDialog(String titel) {
    		this.titel = titel;
    	}
    	/**
    	 * Tonen van een tekst in een dialoogvenstertje. 
    	 * @param message een String met een te tonen berichtje.
    	 * @param output een String met de te tonen tekst.
    	 */
    	public void showString(String message, String output) {
    		JOptionPane.showMessageDialog(
    			null,
    			message + "\n\n" + output + "\n\n",
    			titel,
    			JOptionPane.PLAIN_MESSAGE);
    
    	}
    
    	/**
    	* Tonen van een geheel getal in een dialoogvenstertje.  
    	* @param message een String met een te tonen berichtje.
    	* @param een int met het te tonen getal.
    	*/
    	public void showInteger(String message, int getal) {
    		JOptionPane.showMessageDialog(
    			null,
    			message + "\n\n" + Integer.toString(getal) + "\n\n",
    			titel,
    			JOptionPane.PLAIN_MESSAGE);
    
    	}
    
    	/**
    	* Tonen van een geheel getal in een dialoogvenstertje.
    	* @param message een String met een te tonen berichtje.  
    	* @param een double met het te tonen getal.
    	*/
    	public void showDouble(String message, double getal) {
    		JOptionPane.showMessageDialog(
    			null,
    			message + "\n\n" + Double.toString(getal) + "\n\n",
    			titel,
    			JOptionPane.PLAIN_MESSAGE);
    	}
    
    	/**
    	 * Inlezen van een String.
    	 * @param message een String met de tekst die in het dialoogvenster
    	 * moet getoond worden.
    	 * @return de ingelezen String.  Indien het venster zonder
    	 * invoer wordt afgesloten is de String null.
    	 */
    	public String readString(String message) {
    		Object[] possibilities = null;
    		String s = null;
    		s =
    			(String) JOptionPane.showInputDialog(
    				null,
    				message,
    				this.titel,
    				JOptionPane.PLAIN_MESSAGE,
    				null,
    				possibilities,
    				"");
    
    		if ((s == null) || (s.length() == 0)) {
    			s = null;
    		}
    		return s;
    	}
    
    	/**
    	 * Inlezen van een geheel getal.
    	 * @param message een String met de tekst die in het dialoogvenster
    	 * moet getoond worden.
    	 * @return het ingelezen geheel getal (een int).  Indien het venster zonder
    	 * correcte invoer wordt afgesloten is het getal 0 (nul).
    	 */
    	public int readInteger(String message) {
    		boolean isAnInteger = false;
    		String tekst = null;
    		int gelezen = 0;
    		while (!isAnInteger) {
    			tekst = readString(message);
    			if (tekst != null) {
    				try {
    					gelezen = Integer.parseInt(tekst);
    					isAnInteger = true;
    				} catch (NumberFormatException nfe) {
    					isAnInteger = false;
    				}
    			} else {
    				isAnInteger = true;
    				gelezen = 0;
    			}
    		}
    		return gelezen;
    	}
    
    	/**
    	 * Inlezen van een kommagetal.
    	 * @param message een String met de tekst die in het dialoogvenster
    	 * moet getoond worden.
    	 * @return het ingelezen getal (een double).  Indien het venster zonder
    	 * correcte invoer wordt afgesloten is het getal 0.0 (nul).
    	 */
    	public double readDouble(String message) {
    		boolean isADouble = false;
    		String tekst = null;
    		double gelezen = 0.0;
    		while (!isADouble) {
    			tekst = readString(message);
    			if (tekst != null) {
    				try {
    					gelezen = Double.parseDouble(tekst);
    					isADouble = true;
    				} catch (NumberFormatException nfe) {
    					isADouble = false;
    				}
    			} else {
    				isADouble = true;
    				gelezen = 0.0;
    			}
    		}
    		return gelezen;
    	}
    
    	/**
    	 * Wanneer je in je programma geen uitvoer meer nodig hebt 
    	 * MOET je deze bewerking op het SimpleInOutDialog-object uitvoeren.
    	 * Het programma wordt dan be�indigd.
    	 */
    	public void stop() {
    		System.exit(0);
    	}
    
    }
    Last edited by Aname; 08-21-2012 at 04:28 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Stuck with my inheritance java testing :'(

    I see a lot of un-formatted code above, but I don't see any specific clear cut questions. To improve our ability to help you, please wrap your posted code in [code] [/code] tags (note that the top code tag is different from the bottom one), and please ask a specific answerable question. If you have any error messages, please post those as well.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Stuck with my inheritance java testing :'(

    Also, I see that you received a helpful answer to your previous question but never replied back. Please do so now since volunteers like to know that their time and effort trying to help you wasn't wasted, that you took the time to read their reply and appreciate their trying to help you. Thanks.

  4. #4
    Aname is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: Stuck with my inheritance java testing :'(

    alright i edited my question

    The SimpleInOutDialog is just a script to get prompt boxes like in html style

  5. #5
    Aname is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: Stuck with my inheritance java testing :'(

    My apologizes for not replying back after an answer, i greatly appreciate the offer of all volunteers that help others, i learn alot from other on this website, from common questions and answers. i think i will read the rules of this forum just to respect others and appreciate their effort of putting time into others questions

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Stuck with my inheritance java testing :'(

    I wouldn't bother with the SimpleInOutDialog class, but would simply use a JOptionPane that would allow the user to input information, a JOptionPane.showInputDialog, and would then parse the String returned (first checking that it's not null) into an int via Integer.parseInt(...).
    Last edited by Fubarable; 08-21-2012 at 04:41 AM.

  7. #7
    Aname is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: Stuck with my inheritance java testing :'(

    Yes i could, thanks for saying, however i would like to use this SimpleInOutdialog Class first to make a few tests just in order to understand java better
    For example using that code from the class simpleInOutDialog in order to get something from another class into the main
    Last edited by Aname; 08-21-2012 at 04:48 AM.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Stuck with my inheritance java testing :'(

    Well if you must use that class, there's a method in it which should help you get int input. Have you tried it yet?

  9. #9
    Aname is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: Stuck with my inheritance java testing :'(

    i tryed this
    Java Code:
    package testing;
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		double Acredits, Somecredits;
    		
    		SimpleInOutDialog InOut;
    		InOut = new SimpleInOutDialog("something");
    		
    		Person P = new Person("willy");
    		System.out.println(P);
    		Person A = new Person("");
    		A.setName("wilson");
    		System.out.println(A);
    		
    		Student harry = new Student ("harry potter");
    		Student Ron = new Student ("Ron");
    	
    		
    		Acredits = InOut.readDouble("Give me some credits");
    		Student hermelien = new Student ("hermelientje potter");
    		Somecredits = hermelien.getCredits();
    		InOut.showDouble("your credits are", Somecredits);
    		
    		Employee marian = new Employee("mariannetje");
    		marian.setSalary(1000);
    		System.out.println(marian.getSalary());
    		System.out.println(harry);
    		System.out.println(Ron);
    		System.out.println(hermelien);
    		
    	}
    }
    and also made double credits instead of int credits in student class.
    I get a popup box but i dont receive any answer it remains 0,0
    for example i get "your credits are 0,0

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Stuck with my inheritance java testing :'(

    OK, in this code:
    Java Code:
             
            Acredits = InOut.readDouble("Give me some credits");
            Student hermelien = new Student ("hermelientje potter");
            Somecredits = hermelien.getCredits();
            InOut.showDouble("your credits are", Somecredits);
    You get the user's input for credits, you create a new Student object, but you haven't yet given the credits to the Student, and it won't magically assimilate them. If only Student had a method that would allow you to set its credits,... if only.....

  11. #11
    Aname is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: Stuck with my inheritance java testing :'(

    hahaha xD thank you sooo much i finnaly found it, i learned new things today. thank you very much. i got so worked up its even 5o clock in the morning here xD

    i wanted to solve my mystery of my puzzle :)

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Stuck with my inheritance java testing :'(

    Quote Originally Posted by Aname View Post
    Java Code:
     * @author Jan Beurghs<br>
     * 17-mei-2004<br>
    Have you really been working on this code for more than eight years? Or have you 'borrowed' this code from somewhere else?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    Aname is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: Stuck with my inheritance java testing :'(

    Quote Originally Posted by JosAH View Post
    Have you really been working on this code for more than eight years? Or have you 'borrowed' this code from somewhere else?

    kind regards,

    Jos
    i have used the code from a cd that came with a book of java that i bought, there was also some other stuff for example to install Eclipse and other small exercices.

Similar Threads

  1. Junit testing, testing list<e> interface
    By mackavelirip in forum New To Java
    Replies: 0
    Last Post: 10-05-2011, 07:08 AM
  2. testing Java jsp/servlets
    By cgodfrey in forum New To Java
    Replies: 1
    Last Post: 03-30-2011, 10:07 PM
  3. Serialized Java Obj testing
    By akokane in forum New To Java
    Replies: 0
    Last Post: 02-02-2011, 07:38 AM
  4. java UI web testing tool
    By roanmv in forum Forum Lobby
    Replies: 1
    Last Post: 10-15-2009, 12:20 PM
  5. Java testing tools
    By mew in forum Advanced Java
    Replies: 0
    Last Post: 01-25-2008, 08:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •