#1  
Antiguo January 17, 2013, 04:51 PM
Avatar de Jessica
Jessica Jessica no está en línea
...
 
Fecha de Ingreso: Jun 2008
Ubicación: PA
Mensajes: 8,187
Primera Lengua: English, Chinese
Jessica is on a distinguished road
Java application

I'm taking a java course in college, and this is the second week...and I'm already having trouble understanding. My first application is not going well. I'm hoping to get some assistance. :/ I am completely clueless.

The Application:
Write a simple class called PointChecker that will
1) Declare a variable as a Point
2) Using the constructor that has two double parameters construct a point at location 93,67
3) Using the methods getX and getY and the System.out.print and println methods output the actual values that the created point contains
4) The output the expected values (what you expect to see)
5) Then using the translate method move the x coordinate 13 to the left (negative) and the Y value 7 down (positive).
6) Output values as described in steps 3 and 4


This is completely wrong, I know, but it's what I came up with. :/
Código:
package course.jzc22.lab01;

public class PointTester {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
			int myPoint; }
			public int X;
			public int Y;
			myPoint.X = 93;
			myPoint.Y = 67;
		public void getX (int X) {
			X = 
			System.out.println("Point");
	}

}
Responder Con Cita
   
Quita esta publicidad al registrarte con una cuenta gratuita en Tomísimo.
  #2  
Antiguo January 17, 2013, 06:08 PM
Avatar de chileno
chileno chileno no está en línea
Diamond
 
Fecha de Ingreso: Feb 2009
Ubicación: Las Vegas, USA
Mensajes: 7,863
Primera Lengua: Castellano
chileno is on a distinguished road
Cita:
Escrito originalmente por Jessica Ver Mensaje
I'm taking a java course in college, and this is the second week...and I'm already having trouble understanding. My first application is not going well. I'm hoping to get some assistance. :/ I am completely clueless.

The Application:
Write a simple class called PointChecker that will
1) Declare a variable as a Point
2) Using the constructor that has two double parameters construct a point at location 93,67
3) Using the methods getX and getY and the System.out.print and println methods output the actual values that the created point contains
4) The output the expected values (what you expect to see)
5) Then using the translate method move the x coordinate 13 to the left (negative) and the Y value 7 down (positive).
6) Output values as described in steps 3 and 4


This is completely wrong, I know, but it's what I came up with. :/
Código:
package course.jzc22.lab01;

public class PointTester {

    /**
     * @param args
     */
    public static void main(String[] args) {
            int myPoint; }
            public int X;
            public int Y;
            myPoint.X = 93;
            myPoint.Y = 67;
        public void getX (int X) {
            X = 
            System.out.println("myPoint");
    }

}
I really don't know, but shouldn't you println myPoint instead of just Point?
Responder Con Cita
  #3  
Antiguo January 17, 2013, 10:39 PM
Avatar de wrholt
wrholt wrholt no está en línea
Sapphire
 
Fecha de Ingreso: Apr 2011
Ubicación: Boston, Massachusetts, USA
Mensajes: 1,401
Primera Lengua: US English
wrholt is on a distinguished road
Cita:
Escrito originalmente por Jessica Ver Mensaje
I'm taking a java course in college, and this is the second week...and I'm already having trouble understanding. My first application is not going well. I'm hoping to get some assistance. :/ I am completely clueless.
I've never worked with Java, but reading it isn't a problem for me: Java is closely related to other languages that I've used professionally for years.
I won't do your homework for you, of course, but I'm happy to give you some pointers.

You're right, what you've written doesn't do the job. You have a LOT of syntax (grammar) errors in your code.


Cita:
Escrito originalmente por Jessica Ver Mensaje
The Application:
Write a simple class called PointChecker that will
1) Declare a variable as a Point
2) Using the constructor that has two double parameters construct a point at location 93,67
3) Using the methods getX and getY and the System.out.print and println methods output the actual values that the created point contains
4) The output the expected values (what you expect to see)
5) Then using the translate method move the x coordinate 13 to the left (negative) and the Y value 7 down (positive).
6) Output values as described in steps 3 and 4


This is completely wrong, I know, but it's what I came up with. :/
Código:
package course.jzc22.lab01;
 
public class PointTester { // Wrong name according to instructions
 
    /**
     * @param args
     */
    public static void main(String[] args) {
            int myPoint; }
 
/**
* main() ends with the first '}'. The only program statement inside 
* main() is the declaration of the variable 'myPoint', of type integer.
* As main() contains no statements to print anything, running it will 
* just return without producing any output.
*/ 
 
            public int X;
            public int Y;
 
/**
* You've declared two public properties for your class:
* property 'X' of type integer.
* property 'Y' of type integer.
*/
 
            myPoint.X = 93;
            myPoint.Y = 67;
/**
* These two lines look like assignment statements to set the values 
* of the properties 'X' and 'Y' for some object variable names 'myPoint'.
* However:
* 1. These statements are NOT inside of a function.
* 2. The variable 'myPoint' is not defined/does not exist here.
*     (The variable "myPoint" inside the function main() exists only inside
*     the function. It does not exist outside the function.
*/ 
 
        public void getX (int X) {
            X = 
            System.out.println("Point");
 
        /**
          * Syntax error: the method println() prints its arguments,
          * but it doesn't return a value. It CANNOT be used to asign
          * a value to the variable 'X'.
          *
          * The argument to println() is the string constant "Point".
          * println() will print the string constant exactly.
          */
    }
 
/**
* You have written a public method (a function) named "getX" 
* of type "void" (which means that your funtion getX() does not 
* return a value). However, nothing calls your function, so it never runs.
*/
 
} // '}' ends your class
Suggestions:

a. Your class should contain the main() function. All of your code should be inside your main() function; that is, between the '{' that follows the declaration of main() and the '}' that ends the function body. The main() function itself should be the only thing inside the body of your class (that is, inside the sequence of '{' and '}' that mark the beginning and end of the body of the class).

b. Each numbered instruction tells you what statement (or group of statements) should come next inside your main() function.

Reviewing your instructions:


The Application:

Write a simple class called PointChecker that will

1) Declare a variable as a Point (What does a variable declaration look like? How do you define a variable that holds a value whose type is the class Point?)

2) Using the constructor that has two double parameters construct a point at location 93,67 (What does the constructor look like? How do you create a variable for the class Point?)

3) Using the methods getX and getY and the System.out.print and println methods output the actual values that the created point contains (The class Point defines the methods getX and getY. You invoke those functions by using a variable whose value is an instance of the class Point. What does that look like?)

4) The output the expected values (what you expect to see) (The package 'system.out' provides the methods 'system.out.print' and 'system.out.println'. They print the arguments that are inside the parentheses. The arguments may be literal constants, or they may be the names of variables. What do literal constants look like? What do variable names look like?)

5) Then using the translate method move the x coordinate 13 to the left (negative) and the Y value 7 down (positive). (The class Point also implements a method called translate. You invoke it by using a variable whose value is an instance of the class Point. The method has 2 arguments: the amount to add to the X axis, and the amount to add to the Y axis. The values to add may be positive, negative or zero. Invoking the method adds the specified values to the corresponding X and Y property values.)

6) Output values as described in steps 3 and 4 (Repeat the same type of code you used in steps 3 and 4 in order to write out the new (translated) coordinate values of the variable of type class Point against which you invoked the translate function in step 5.)

Let us know whether any of this helps.

Última edición por wrholt fecha: January 17, 2013 a las 10:45 PM
Responder Con Cita
  #4  
Antiguo January 18, 2013, 01:23 AM
Avatar de pjt33
pjt33 pjt33 no está en línea
Diamond
 
Fecha de Ingreso: Aug 2009
Ubicación: Valencia, España
Mensajes: 2,600
Primera Lengua: Inglés (en-gb)
pjt33 is on a distinguished road
Cita:
Escrito originalmente por wrholt Ver Mensaje
4) The output the expected values (what you expect to see) (The package 'system.out' provides the methods 'system.out.print' and 'system.out.println'. They print the arguments that are inside the parentheses. The arguments may be literal constants, or they may be the names of variables. What do literal constants look like? What do variable names look like?)
Small correction: the class System* has a static field out whose class** provides methods print and println.

PS You might want to
Código:
import java.awt.Point;
* java.lang.System, to give it its full name.

** java.io.PrintStream

Última edición por pjt33 fecha: January 18, 2013 a las 01:27 AM
Responder Con Cita
  #5  
Antiguo January 18, 2013, 07:16 AM
Avatar de wrholt
wrholt wrholt no está en línea
Sapphire
 
Fecha de Ingreso: Apr 2011
Ubicación: Boston, Massachusetts, USA
Mensajes: 1,401
Primera Lengua: US English
wrholt is on a distinguished road
Cita:
Escrito originalmente por pjt33 Ver Mensaje
Small correction: the class System* has a static field out whose class** provides methods print and println.

PS You might want to
Código:
import java.awt.Point;
* java.lang.System, to give it its full name.

** java.io.PrintStream
Thanks, pjt33!

I noticed that the first line of code in Jessica's program is:

Código:
package course.jzc22.lab01;
I wouldn't be surprised to learn that this package includes some of the common imports. But then again, I wouldn't be surprised to learn that it doesn't.
Responder Con Cita
  #6  
Antiguo January 18, 2013, 01:17 PM
Avatar de pjt33
pjt33 pjt33 no está en línea
Diamond
 
Fecha de Ingreso: Aug 2009
Ubicación: Valencia, España
Mensajes: 2,600
Primera Lengua: Inglés (en-gb)
pjt33 is on a distinguished road
Cita:
Escrito originalmente por wrholt Ver Mensaje
I wouldn't be surprised to learn that this package includes some of the common imports. But then again, I wouldn't be surprised to learn that it doesn't.
That's the namespace of Jessica's class, and I'd be prepared to bet that jzc22 is her college-assigned username.
Responder Con Cita
Respuesta

 

Link to this thread
URL: 
HTML Link: 
BB Code: 

Normas de Publicación
No puedes crear nuevos hilos
No puedes enviar respuestas
No puedes adjuntar archivos
No puedes editar tus mensajes
Código BB está habilitado
Los iconos gestuales están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Normas del Sitio

Temas Similares
Tema Autor de Tema Foro Respuestas Último mensaje
Application? workingmom20 Modismos y Dichos 2 September 03, 2008 11:21 PM


La franja horaria es GMT -6. Ahora son las 08:14 AM.

Foro powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.

X