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 3 of 3

Thread: Feedback on java assignment

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Feedback on java assignment

    Hi,

    I have just started to learn Java and programming in general from different youtube videos. I am currently working on the assignments from here stanford.edu/class/cs106a/handouts/13-assignment-2.pdf and I would be happy if I could get some feedback on the code I have written.

    Assignment 3

    import acm.program.*;

    public class FindRange extends ConsoleProgram {
    public void run() {
    println("This program finds the largets and smallest numbers that the user put in, enter 0 to stop the program");

    double inmatat = 1;
    double large = 0;
    double small = 1;
    int counter = 0;
    while (inmatat != 0){

    if (inmatat > large){
    large = inmatat;
    }
    if (counter == 1 ){
    small = inmatat;
    }

    if (inmatat < small){
    small = inmatat;
    }
    counter++;
    inmatat = readInt("Enter n1; ");
    }

    if ( counter !=1){
    println("The largets number is " + large);
    println("The smallest numbers is " + small);
    }
    else {
    println("The program was stoped without any numbers input from user");
    }
    }
    }


    Assignment 4

    import acm.graphics.*;
    import acm.program.*;
    import java.awt.*;

    public class Target extends GraphicsProgram {
    public void run() {
    GOval circle1 = new GOval(100, 20, 144, 144);
    circle1.setFilled(true);
    circle1.setFillColor(Color.RED);
    circle1.setColor(Color.RED);
    add (circle1);
    GOval circle2 = new GOval(125.2, 45.2, 93.6, 93.6);
    circle2.setFilled(true);
    circle2.setFillColor(Color.WHITE);
    circle2.setColor(Color.WHITE);
    add (circle2);
    GOval circle3 = new GOval(150.4, 70.4, 43.2, 43.2);
    circle3.setFilled(true);
    circle3.setFillColor(Color.RED);
    circle3.setColor(Color.RED);
    add (circle3);

    }
    }






    Assignment 5

    import acm.graphics.*;
    import acm.program.*;
    import java.awt.*;



    public class ProgramHierarchy extends GraphicsProgram {
    public void run() {

    double widht = 200;
    double height = 80;

    GRect rek1 = new GRect(getWidth()/2-widht/2, getHeight()/2-3*(height), widht, height);
    add (rek1);
    GRect rek2 = new GRect(getWidth()/2-widht/2, getHeight()/2-(height), widht, height);
    add (rek2);
    GRect rek3 = new GRect(getWidth()/2-2*widht, getHeight()/2-(height), widht, height);
    add (rek3);
    GRect rek4 = new GRect(getWidth()/2+widht, getHeight()/2-(height), widht, height);
    add (rek4);

    GLine linjeRek3TillRek1 = new GLine(( getWidth()/2)-(1.5*widht), (getHeight()/2)-(height), getWidth()/2, getHeight()/2-2*(height));
    add (linjeRek3TillRek1);

    GLine linjeRek2TillRek1 = new GLine( getWidth()/2, getHeight()/2-(height), getWidth()/2, getHeight()/2-2*(height));
    add (linjeRek2TillRek1);

    GLine linjeRek4TillRek1 = new GLine( getWidth()/2+(1.5*widht), getHeight()/2-(height), getWidth()/2, getHeight()/2-2*(height));
    add (linjeRek4TillRek1);


    GLabel label = new GLabel("Program");
    label.setLocation(getWidth()/2-label.getWidth()/2, getHeight()/2-(2.5*(height)));
    add(label);

    GLabel label2 = new GLabel("GraphicsProgram");
    label2.setLocation(getWidth()/2-label.getWidth(), getHeight()/2-(height/2));
    add(label2);

    GLabel label3 = new GLabel("ConsoleProgram");
    label3.setLocation(getWidth()/2-1.5*widht-label.getWidth(), getHeight()/2-(height/2));
    add(label3);

    GLabel label4 = new GLabel("DialogProgram");
    label4.setLocation(getWidth()/2+1.5*widht-label.getWidth(), getHeight()/2-(height/2));
    add(label4);



    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Feedback on java assignment

    When posting code, please use the highlight tags.

    You also might want to split this up into multiple questions, with the question for each assignment along with the code. Make it easy for people to help you, and you'll be more likely to receive better help.

    But really, I wouldn't worry too much about making the code perfect at this point. There a million ways to accomplish any given goal. Does the code do what the assignment asked? If so, good. Besides, anything you write now will look terrible to you in 6 months (this fact never changes, even after a decade of programming), so it doesn't make a ton of sense to waste a lot of time making it perfect. Instead, keep practicing! Write more programs, or modify these programs to do something else. That's a much better use of your time than making sure your syntax is perfect.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    MadMulken (July 3rd, 2013)

  4. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Feedback on java assignment

    Yes the code does what the assignment is asking for. So I will take your advice and spend my time writing more programs and modify the ones that I have done.

    Thanks for the help!

Similar Threads

  1. Replies: 0
    Last Post: April 5th, 2013, 10:20 AM
  2. Replies: 0
    Last Post: December 12th, 2012, 09:02 PM
  3. UML Feedback?
    By behedwin in forum Object Oriented Programming
    Replies: 2
    Last Post: October 13th, 2012, 11:13 AM
  4. My New Website | Feedback Please!
    By OA-OD-JD1 in forum Totally Off Topic
    Replies: 3
    Last Post: July 16th, 2012, 01:30 AM
  5. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM