Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: my java assignment -- please help

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default my java assignment -- please help

    I am quite new to java, and now I have a problem -- my teacher wants us to do a java assignment.

    Here are the details:
    Make a class diagram and an object diagram for creating users or customers or products etc. (just an object example and work on it)

    Implement class diagram in Java and include these:
    (a)
    At least 2 constructors
    Get and Set accessor methods (accessor and mutators) for all relevant attributes. You may want to do error checkings in these methods, if necessary

    Any methods that you think would be required.
    For example, if you wrote a “User” class, then you might need to write a method:
    public boolean authenticate(String pwd) { … }

    (b)
    Create a Java application (with the main() method) that uses the class you created in (a):
    Use two different constructors, create at least 2 objects from the class in (a)
    Call all the methods that you have created in (a). Use the mutators to change the attributes, and use the accessor to get the attributes.

    I not sure how to do, and neither do I know how to use the codes.

    Please help. If possible, share with me your codings for my assignment.
    I am really left with no choice already.

    I doing it on Eclipse JavaEE


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: my java assignment -- please help

    So what is the difficulty you have with this? You should realise we won't do your assignment for you, but we can help you when you get stuck.

    Post up the code you have so far, and explain where you are stuck. If you get any error messages, post up the full text of the message.

  3. #3
    Member
    Join Date
    May 2010
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 12 Posts

    Default Re: my java assignment -- please help

    here is a small example in java se, hope you got the idea

    public class User {
    	private String user;
    	private String passwd;
     
    	// constructor 1, take user and pw
    	public User(String user, String passwd) {
    		this.user = user;
    		this.passwd = passwd;
    	}
     
    	// constructor 2, take only user
    	public User(String user) {
    		this.user = user;
    		this.passwd = null;
    	}
     
    	public void setUser(String user) {
    		this.user = user;
    	}
     
    	public String getUser() {
    		return this.user;
    	}
     
    	public String getPasswd() {
    		return this.passwd;
    	}
     
    	public void setPasswd(String passwd) {
    		int minLength = 8;
    		if (passwd.length() < minLength) {
    			System.out.println("Password must have at least 8 digits");
    		} else {
    			this.passwd = passwd;
    		}
    	}
     
    	public boolean authenticate(String pwd) {
    		if (this.passwd == null) {
    			System.out.println("Authentication failed. Password not set.");
    			return false;
    		} else if (this.passwd.equals(pwd)) {
    			System.out.println("Authentication successfull.");
    			return true;
    		}
    		System.out.println("Authentication failed. Invalid password");
    		return false;
    	}
     
    	public static void main(String[] args) {
    		// call first constructor
    		User user1 = new User("user1", "password1");
    		// call seconde constructor
    		User user2 = new User("user2");
    		// Authentication should fail
    		user2.authenticate("hallo");
    		// Password too short, not set
    		user2.setPasswd("mypass");
    		// New password accepted
    		user2.setPasswd("password2");
    		// Authentication succesfull
    		user2.authenticate("password2");
    		// Authentication ok for user1
    		user1.authenticate("password1");
    		user1.setPasswd("newpassword");
    		// user1 try with old one, Auth. failed
    		user1.authenticate("password1");
    		// user1 retry with the right one
    		user1.authenticate("newpassword");
    	}
    }

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: my java assignment -- please help

    thanks j2me64 for your help. anyway i have figured out my codings and it is quite different from yours.

    Problem !
    So now, I am trying to open my project.

    I start up eclipse, and there, at the ''select a workspace'' part, i browser to this:
    C:\Users\Personal\Desktop\Feedback (this is where my project, named Feedback, is saved). Then I click ok.

    However, after I click ok, and eclipse loads itself, under Project Explorer, there is nothing at all. Where has my project Feedback gone to ?

    I can't open my project !

    Please help.

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: my java assignment -- please help

    Try refreshing your Eclipse workspace. If that doesn't work, create a new workspace and import the Project using Eclipse's import function.

  6. #6
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: my java assignment -- please help

    I think you want to open up a workspace located at C:\Users\Personal\Desktop

    That should show your project called Feedback if it has been set up as an eclipse project that is.

    // Json

  7. #7
    Junior Member
    Join Date
    May 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: my java assignment -- please help

    I am stuck at this part.

    (part c)
    A Java application (with the main() method) that uses the class you created in (part b):
    Using two different constructors, create at least 2 objects from the class in (part b)
    Call all the methods that you have created in (part b). Use the mutators to change the attributes, and use the accessor to get the attributes.

    (look at my starting post for part B requirements.)

    How do I do it ? Seriously, I have no idea how. I feel very desperate nowfor answers

    here are the codings (two java files)

    Feedback.java
    public class Feedback {
    private String Name;
    private String Topic;
    private String Description;

    public String getName(){
    return Name;
    }
    public String getTopic(){
    return Topic;
    }
    public String getDescription(){
    return Description;
    }

    public void setName (String n){
    Name= n;
    }
    public void setTopic (String T){
    Topic= T;
    }
    public void setDescription (String D){
    Description= D;
    }
    }
    TestFeedback.java
    public class TestFeedback {
    public static void main(String[] args){
    Feedback U1 = new Feedback ();
    U1.setName("Ah Huat");
    U1.setTopic ("Topic : Compliment");
    U1.setDescription ("Your company has provided good services, and your website is well built.");

    Feedback U2 = new Feedback ();
    U2.setName ("Ah Hia");
    U2.setTopic ("Topic : Suggestion");
    U2.setDescription ("May I suggest that the company change the script of the website, as well as the fonts used for the word ? I find it hard to navigate your website. Thanks a lot");

    System.out.println (U1.getName());
    System.out.println (U1.getTopic());
    System.out.println (U1.getDescription());

    System.out.println (U2.getName());
    System.out.println (U2.getTopic());
    System.out.println (U2.getDescription());

    }
    }
    I am weak in java, so can help me check have I fulfilled Part A, B and Part C or not
    Or have I miss out any of the three parts or miss out any requirements

    ?

Similar Threads

  1. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  2. Beginner needs help with simple java assignment.
    By joachim89 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2010, 07:53 PM
  3. I need extensive help with my java assignment
    By MoshMoakes in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 12th, 2009, 07:44 PM
  4. Replies: 1
    Last Post: May 8th, 2009, 09:55 AM
  5. [SOLVED] Problem with Grading calculator in java program
    By Peetah05 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: March 28th, 2009, 05:25 PM