View Full Version : Urgent!! need help from a JAVA programmer
ArManI
06-10-2007, 01:11 PM
i have to do this assignment due monday night but i'm so lost in creating classes... (date on the paper is wrong, teacher gave an extension)
if any of you who knows programing in c++ or java language, and have 30min to spare, please help me construct the program!
Thanks a lot, appreciate a lot
http://i40.photobucket.com/albums/e229/superarmani/File0002.jpg
http://i40.photobucket.com/albums/e229/superarmani/File0001-1.jpg
ds2chan
06-10-2007, 01:22 PM
here's a sample java class.. if you need anymore help or clarification just post it up here.. I have to go for lunch right now so I'll check back when I get back..
public class Practice {
int someInt_1;
int someInt_2;
String someStr_1;
String someStr_2;
public Practice()
{
someInt_1 = 0;
someInt_2 = 0;
someStr_1 = "";
someStr_2 = "";
}
public Practice(int value_1, int value_2)
{
someInt_1 = value_1;
someInt_2 = value_2;
someStr_1 = "";
someStr_2 = "";
}
public Practice(String value_1, String value_2)
{
someInt_1 = 0;
someInt_2 = 0;
someStr_1 = value_1;
someStr_2 = value_2;
}
public void write_someInt_1(int value)
{
someInt_1 = value;
}
public void write_someInt_2(int value)
{
someInt_2 = value;
}
public void write_someStr_1(String value)
{
someStr_1 = value;
}
public void write_someStr_2(String value)
{
someStr_2 = value;
}
public int get_someInt_1()
{
return someInt_1;
}
public int get_someInt_2()
{
return someInt_2;
}
public String get_someStr_1()
{
return someStr_1;
}
public String get_someStr_2()
{
return someStr_2;
}
}
ArManI
06-10-2007, 02:43 PM
so far i got this... anything not logic?
still dont know what should i include in the constractor
and im not sure if i do it right in the setAtibutes() method, can i ask for user's input inside a method? is it the right way to set attributes?
import java.util.Scanner;
public class Quadrilateral {
private int x1, x2, x3, x4, y1, y2, y3, y4;
private double length12, length23, length34, length41, angle214;
public Quadrilateral(){
}
public int setAttributes(){
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter the coordinates of the 4 points (clockwise)");
System.out.print("(x1,y1) :");
x1=keyboard.nextInt();
y1=keyboard.nextInt();
System.out.print("(x2,y2) :");
x2=keyboard.nextInt();
y2=keyboard.nextInt();
System.out.print("(x3,y3) :");
x3=keyboard.nextInt();
y3=keyboard.nextInt();
System.out.print("(x4,y4) :");
x4=keyboard.nextInt();
y4=keyboard.nextInt();
return x1;
return x2;
return x3;
return x4;
return y1;
return y2;
return y3;
return y4;
}
public double computeLength(){
length12 = Math.sqrt(((x2-x1)*(x2-x1)) + ( (y2-y1)* (y2-y1) ));
length23 = Math.sqrt(((x3-x2)*(x3-x2)) + ( (y3-y2)* (y3-y2) ));
length34 = Math.sqrt(((x4-x3)*(x4-x3)) + ( (y4-y3)* (y4-y3) ));
length41 = Math.sqrt(((x1-x4)*(x1-x4)) + ( (y1-y4)* (y1-y4) ));
return length12, length23, length34, length41;
}
public double computeAngle(){
angle214 = Math.acos( ((x2-x1) * (x4-x1) + (y2-y1) * (y4-y1))/(length12*length41) );
angle214 = Math.toDegrees(angle214);
return angle214;
}
public boolean allSidesEqual(){
return ((length12 == length23) && (length12 == length34) && (length12 == length41));
}
public boolean oppositeSidesEqual(){
return ((length12 == length34) && (length23 == length41));
}
public boolean checkRightAngle(){
return (angle214 == 90);
}
public void classify(){
if(allSidesEqual() && oppositeSidesEqual() && checkRightAngle())
System.out.println("this is a SQAURE");
if(oppositeSidesEqual() && checkRightAngle())
System.out.println("this is a RECTANGLE");
if(allSidesEqual() && oppositeSidesEqual())
System.out.println("this is a RHOMBUS");
if(oppositeSidesEqual())
System.out.println("this is a PARALLELOGRAM");
if(!allSidesEqual() && !oppositeSidesEqual())
System.out.println("this is an OTHER type or an irregular quadrilateral");
}
ds2chan
06-10-2007, 03:51 PM
the constructor is used to declare and/or initialize your variables.. if you have already delcared your variables (like I did in my example), then you need to initialize them in the constructor..
so, in my example I set all my variables that are integers to 0 and set all my strings to a blank string.. you can also set objects to null or whatever you want..
in your setAttributes method you're returning 8 integers.. only the first one will get returned.. you should not need to return anything in this method.. so change it to look like this..
public void setAttributes(){
<code>;
<remove return statements>;
}
ArManI
06-10-2007, 04:05 PM
update!
CLASS1:
import java.lang.Math;
import java.util.Scanner;
public class Quadrilateral {
private int x1, x2, x3, x4, y1, y2, y3, y4;
private double length12, length23, length34, length41, angle214;
String type;
Scanner keyboard=new Scanner(System.in);
public Quadrilateral(){
}
public void setAttributes(){
System.out.println("Enter the coordinates of the 4 points (clockwise)");
System.out.print("(x1,y1) :");
x1=keyboard.nextInt();
y1=keyboard.nextInt();
System.out.print("(x2,y2) :");
x2=keyboard.nextInt();
y2=keyboard.nextInt();
System.out.print("(x3,y3) :");
x3=keyboard.nextInt();
y3=keyboard.nextInt();
System.out.print("(x4,y4) :");
x4=keyboard.nextInt();
y4=keyboard.nextInt();
}
public void computeLength(){
length12 = Math.sqrt(((x2-x1)*(x2-x1)) + ( (y2-y1)* (y2-y1) ));
length23 = Math.sqrt(((x3-x2)*(x3-x2)) + ( (y3-y2)* (y3-y2) ));
length34 = Math.sqrt(((x4-x3)*(x4-x3)) + ( (y4-y3)* (y4-y3) ));
length41 = Math.sqrt(((x1-x4)*(x1-x4)) + ( (y1-y4)* (y1-y4) ));
System.out.println("length 1-2 = " +length12);
System.out.println("length 2-3 = " +length23);
System.out.println("length 3-4 = " +length34);
System.out.println("length 4-1 = " +length41);
}
public void computeAngle(){
double angle = Math.acos( ((x2-x1) * (x4-x1) + (y2-y1) * (y4-y1))/(length12*length41) );
angle214 = Math.toDegrees(angle);
System.out.println("angle 2-1-4 = " + angle214);
}
public boolean allSidesEqual(){
return ((length12 == length23) && (length12 == length34) && (length12 == length41));
}
public boolean oppositeSidesEqual(){
return ((length12 == length34) && (length23 == length41));
}
public boolean checkRightAngle(){
return (angle214 == 90);
}
public void classify(){
if(allSidesEqual() && oppositeSidesEqual() && checkRightAngle())
type = "SQUARE";
else if(oppositeSidesEqual() && checkRightAngle() && !allSidesEqual())
type = "RECTANGLE";
else if(allSidesEqual() && oppositeSidesEqual() && !checkRightAngle())
type = "RHOMBUS";
else if(!allSidesEqual() && oppositeSidesEqual() && !checkRightAngle())
type = "PARALLELOGRAM";
else
type = "type of irregular quadrilateral";
System.out.println("this is a " +type);
}
}
CLASS2 (driver)
public class RunQuadrilateral {
public static void main(String[] args) {
Quadrilateral test = new Quadrilateral();
test.setAttributes();
test.computeLength();
test.computeAngle();
test.classify();
}
}
ArManI
06-10-2007, 04:09 PM
i did a little tryout, and the program works! Cheesy
but there're too many decimals for the double digit... plus the paper said "Be careful when comparing equality of doubles" i didnt do anything to "be careful", should i modify anything?
TEST DATA + OUTPUT:
Enter the coordinates of the 4 points (clockwise)
(x1,y1) :0 0
(x2,y2) :0 10
(x3,y3) :-2 5
(x4,y4) :-2 -5
length 1-2 = 10.0
length 2-3 = 5.385164807134504
length 3-4 = 10.0
length 4-1 = 5.385164807134504
angle 2-1-4 = 158.19859051364818
this is a PARALLELOGRAM
anything else to suggest?
ArManI
06-10-2007, 04:16 PM
need to go to work now, THANKS A LOT , i might need help for another assignment5 (due on wednesday ), gonna post it up after work (11pm)
MazdaTree
06-10-2007, 05:23 PM
does anyone know shell scripting?
(I also need help for a project:))
whiteomega
06-10-2007, 05:59 PM
i'm being pedagogical here, so please, bear with me. what happens if someone wants to use your Quadrilateral class, but has their own RunQuadrilateral which inputs the values already? they'll end up inputting the values twice, which is frustrating from the user point of view. imagine if you had to type your post twice every time you wanted to post, or send a PM, etc. you'd get annoyed pretty quick, wouldn't you? there *is* a way around this, but that i leave that for the judicious reader.
whiteomega
06-10-2007, 06:00 PM
does anyone know shell scripting?
(I also need help for a project:))
shell scripting for which OS? Windows, Linux, Unix?
MazdaTree
06-10-2007, 09:30 PM
shell scripting for which OS? Windows, Linux, Unix?
hmmm I believe linux although the prof is making us use Knoppix. Which is linux that's booted off a cd. The prof wants us to do it within the vi editor
whiteomega
06-10-2007, 09:36 PM
that would be linux :)
here's a link:
http://www.freeos.com/guides/lsst/
Xerox
06-10-2007, 09:52 PM
hmmm I believe linux although the prof is making us use Knoppix. Which is linux that's booted off a cd. The prof wants us to do it within the vi editor
Have fun with vi!
:wq!
majic
06-11-2007, 08:51 AM
Have fun with vi!
:wq!
you forgot to escape that ;)
MazdaTree.. looks like u could get some help here.. so post up your assignment ;)
vanpatrick81
06-11-2007, 10:30 AM
vi???? man I remember that but I can never remember any of the commands. I just gave up and ended up using nled.
MazdaTree
06-11-2007, 12:11 PM
Part 1
http://i51.photobucket.com/albums/f366/Mazdatree/8414f97f.jpg
http://i51.photobucket.com/albums/f366/Mazdatree/4789a84b.jpg
Part 2
http://i51.photobucket.com/albums/f366/Mazdatree/9c1a360c.jpg
http://i51.photobucket.com/albums/f366/Mazdatree/282881b4.jpg
http://i51.photobucket.com/albums/f366/Mazdatree/28c72a24.jpg
http://i51.photobucket.com/albums/f366/Mazdatree/302148a2.jpg
ArManI
06-11-2007, 04:39 PM
wow....that is much different then java/c language...and much more complicated....
got this one due wednesday (assignment5) and final exam on next wednesday
http://i40.photobucket.com/albums/e229/superarmani/assign5.jpg
whiteomega
06-11-2007, 05:56 PM
ArMani: you may want to try writing this yourself first, and posting what you have on the forums (attach a file if you can, or provide a link, if you can).
we can comment on your program (rather than write the program for you), and you get a chance to try your hand. If you can't get it working by tomorrow, post what you have, and i'll comment on it..
whiteomega
06-11-2007, 06:00 PM
MazdaTree: follow the link i posted, or google "Linux shell scripting" for some introductory stuff. Once you've got Knoppix booted, check out the manual pages (man) on useradd, userdel, passwd and quota. you may also want to check out disk use (du from the command line). there are some other ways to get information about users on the system; these should suffice for now.
(man <topic>)
Powered by vBulletin® Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.