I need huge favor and help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: I need huge favor and help

  1. #1
    Join Date
    Jan 2006
    Posts
    11

    Red face I need huge favor and help

    Hello everybody,

    I am new in Java world and so far I had a lot of dificulties in learning java. To be honest, I still do not know almost anything. However, I have to make some codes for my school but I do not how. I tried and tried but no success. Now I am kind a desperate because I should be finishing those codes by now! Those are very simple codes but....

    Code 1:
    Make appllication that will according to input height, weight and selected gender print the tekst "your weight is ideal", "you should gain some weight etc.

    Code2
    Make three instances of class student and fill the first one with data through constructor, second through set/get and leave third one blank. After that show information about those instances using @override method. (required data name, last name and year of study)

    code 3
    make a program that will calculate the sum of two smallest numbers out of three inputed. ADDITION: same functions but diferent number of inputed numbers.

    code 4
    Make the program for the comparison for the rating list according to the points earn earlier and points awarded of exam by using more classes, input dialogs and information dialogs.

    Those are the codes that should be made. They should be very simple and nothing special. I would appreciate any kind of a help and I am sure that I could learn something from this.

    Can anybody help with these????


    Thanks in advance!

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Most people on this forum could write these "for you", but that is not the purpose of this forum, so they won't.

    What have YOU done toward these school assignments? Any kind of start? Any approach spring to mind?

    You'll get lots of help if you have begun your work and are just needing some pointers.

  3. #3
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    Quote Originally Posted by nspils
    You'll get lots of help if you have begun your work and are just needing some pointers.
    Yeah, definitely. Start with #1, if you run into trouble, show us your work, show us that you at least approached the problem before asking for the answer.

  4. #4
    Join Date
    Jan 2006
    Posts
    11
    Thank you for the comments. I agree with you totally. The problem is that I really do not know from where to start and in which direction to go. I wrote code 2 and sent it for review but I got some directions in advance first.

    Can somebody write me kind a framework so I can at least think about the code, try do fill something, post it back on this forum so you can help me again?

    I really do not know from where to start. Is there posibillity to draw some kind of a chart that would represent the structure of a program so I can try to conect in my head the way program should be written?

    I apprecite all your help people and I know that your critics goes to my benefits! Thank you very much for that!

    Cheers

  5. #5
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    This is probably how your student class should look. (sorry if you already
    are given the Student class and are just assigned to make instances
    of it)
    Code:
    class Student {
        private String firstName;
        private String lastName;
        private int year;
        
        // constructors
        
        // default constructor
        public Student() {
            this.firstName = "Sally";
            this.lastName = "Joe";
            this.year = 2006;
        }
        
        // overloaded constructor
        public Student (String firstName, String lastName, int year) {
            this.firstName = firstName;
            this.lastName = lastName;
            this.year = year;
        }
        
        // setters
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
    
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
    
        public void setYear(int year) {
            this.year = year;
        }
        
        // getters
        public void getFirstName() {
            return this.firstName;
        }
    
        public void getLastName() {
            return this.lastName;
        }
    
        public void getYear() {
            return this.year;
        }
    }
    Last edited by destin; 01-10-2006 at 04:50 PM.

  6. #6
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    Quote Originally Posted by zlajka
    I wrote code 2 and sent it for review but I got some directions in advance first.Cheers
    So post what you've written! We're here to help!

  7. #7
    Join Date
    Jan 2006
    Posts
    11
    Destin thank you very much. The code is similar to what I have wrote. Now I can compare it with mine code and see the mistakes I made.

    Once again, thank you very much!

  8. #8
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    Code2
    Make three instances of class student and fill the first one with data through constructor, second through set/get and leave third one blank. After that show information about those instances using @override method. (required data name, last name and year of study)
    this is only half the assignment... show what you have done.

  9. #9
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    Quote Originally Posted by destin
    this is only half the assignment... show what you have done.
    This is correct..

    The majority of people will not help you unless you show what you have attempted so far!!

  10. #10
    Join Date
    Jan 2006
    Posts
    11
    Hi there!

    as I wrote earlier, I submitted the Code 2 to my profesor and got a lot of negative critics but did not received any help:

    here is what I have submitted:


    /**
    *
    * @author Zlatan Sarkanovic
    */
    public class Student {

    Student[] studenti = new Student[3];
    public void StudentRegistracija()
    {
    studenti[0] = new Student();
    studenti[0].setterMethod("Ime=", "Prezime=", "Godina studija=");
    students[1] = new Student("Ime=", "Prezime=", "Godina studija=");
    students[2] = new Student();
    }
    public static void main(String[] args){new StudentRegister();} }

    class Student
    {
    String ime;
    String prezime;
    int godinaStudija;

    public Student()
    {
    ime = Petar;
    prezime = Peric;
    godinaStudija = 1;
    }
    public Student()
    {
    //this constructor sets the class variables data
    //from the parameter/s
    }

    setterMethod(“Ime=Djuro”, “Prezime=Djuric”, “Godina studija=2”)
    { this.ime = ime;
    this.prezime = prezime;
    this.godinaStudija = godinaStudija;

    getterMethod()
    { this.ime=Student.getIme(Djuro);
    this.prezime=Student.getPrezime(Djuric);
    this.godinaStudija=Student.getGodinaStudija(2);
    }

    @Override public Student toString()
    {
    return "Ime:" +ime + "Prezime:" +prezime + "Godina Studija:" +godinaStudija;
    }
    }
    }


    Names aare written on my local language. For your understanding ime=name, prezime=last name, Godina Studija=year of study

    My profesor mentioned something about using the copy instructor, that I do not have a constructor that receives the parameters of a class, I have two empty constructors but only one is needed, setter and getters are totally incorect, I assinged strings without quotes, declaration of function can not be used for assignemnt ??????? ??? ???



    Thanks guys!

  11. #11
    Join Date
    Jan 2006
    Posts
    11
    One more question!

    I am using NetBeans IDE 4.1 and every single time I try to run a project (even if I find complete project on the net) it woul always show <No main classes found>

    What is the problem? What do I have to do?

    Thanks

  12. #12
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Actually, your professor DID try to help you.

    Have you LOOKED at any Java code that compiles and runs?

    A constructor can be "no argument" or can accept arguments, which will then allow the compiler to create an instance of the class with datamembers initialized with the value(s) of the argument(s).

    A constructor with aruments will look something like this:
    Code:
    public Student( String ime, String prezime, int godinaStudija)
    {
         this ime = ime;
         this.prezime = prezime;
         this.godinaStudija = godinaStudija;
    }

    A "setter" provides the value to be stored in ONE data member of the class. So the structure of a "setter" method definition is:

    Code:
    public void setDataMember(Datatype newValue)
    {
         dataMember = newValue;
    }
    A "getter" retrieves the value of ONE data member of the class. So the structure of a "getter" method declaration is:

    Code:
    public Datatype getDataMember()
    {
    return dataMember;
    }
    Don't use a "setter" to set more than one data member.

    Looks like you were trying to override the "toString" method which your Student class would inherit from java.lang.Object. You need to find the signature of the Object.toString() method and use that same signature - just create your String object to return by creating the following String:

    new String( "Ime: " + ime + " Prezime: " +prezime + " Godina Studija: " + godinaStudija);

    Looks like you have alot of work ahead of you ...
    Last edited by nspils; 01-13-2006 at 05:07 PM.

  13. #13
    Join Date
    Jan 2006
    Posts
    11
    Thank you very much for the comments. I know I have a lot of to learn but I am giving my best. Now I was working on Code 1 (specified on the top) and here is how it looks like:

    import java.io.BufferedInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;


    class weight {


    public static void main(String[] args) {

    double weight;
    double height;
    char gender;
    int idealWeight;
    double quote;
    double lose;
    double gain;


    BufferedReader citac = new BufferedReader(new InputSteramReader(System.in));
    System.out.print("Input your weight:[kg]");
    weight=(new Double(citac.readLine())).doubleValue();
    System.out.print("Input yours height in cm:[cm]");
    height=(new Double(citac.readLine())).doubleValue();
    System.out.print("Input your gender Z/M:");
    gender=(new Char(citac.readLine())).CharValue();

    if (gender.equals("M"))
    quote = 100;
    else quote = 110;
    idealnaWeight = height - quote;
    System.out.print("Your ideal weight is:"+idealWeight+"kg");

    if (idealWeight < weight);
    lose = weight - idealWeight;
    System.out.print("You have:"+lose+"kg over");
    else if (idealWeight > weight);
    gain=idealWeight - weight;
    System.out.print("You should gain:"+gain+"kg");
    else (idealWeight=weight);
    System.out.print("Your weight is ideal!");

    }
    }

    When I try to run it, the compiler displays the message "else" without "if" for last two "else". Because I do not know what is the problem I can not run the program and see if the code is good at all.

  14. #14
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    take out the semi colons at the end of the "if" and "else if" statements - your code might get confusing here - you have not used brackets to delineate the code to be executed if the condition is met - you're going to run into trouble the way you have your code structured.

    Code:
    if (gender.equals("M"))
    {
         quote = 100;
    }
    else
    {
          quote = 110;
    }
    
    idealnaWeight = height - quote;
    System.out.print("Your ideal weight is:"+idealWeight+"kg");
    
    if (idealWeight < weight)
    {
         lose = weight - idealWeight;
         System.out.print("You have:"+lose+"kg over");
    }
    else if (idealWeight > weight)
    {
         gain=idealWeight - weight;
         System.out.print("You should gain:"+gain+"kg");
    }
    else (idealWeight=weight) //LOOK OUT, HERE - correct for comparison, not assignment
    {
         System.out.print("Your weight is ideal!");
    }

  15. #15
    Join Date
    Oct 2005
    Posts
    107
    When I try to run it, the compiler displays the message "else" without "if" for last two "else". Because I do not know what is the problem I can not run the program and see if the code is good at all.

    Since you are obviously new to java, the compiler should be your best friend. Learn to love it and read the messages it gives you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center