• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 04:55
CEST 10:55
KST 17:55
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Maestros of the Game: Week 1/Play-in Preview9[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9
Community News
Weekly Cups (August 25-31): Clem's Last Straw?9Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris46Weekly Cups (Aug 11-17): MaxPax triples again!15Weekly Cups (Aug 4-10): MaxPax wins a triple6
StarCraft 2
General
Weekly Cups (August 25-31): Clem's Last Straw? #1: Maru - Greatest Players of All Time Maestros of the Game: Week 1/Play-in Preview Weekly Cups (Aug 11-17): MaxPax triples again! 2024/25 Off-Season Roster Moves
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris Monday Nights Weeklies LiuLi Cup - September 2025 Tournaments 🏆 GTL Season 2 – StarCraft II Team League $5,100+ SEL Season 2 Championship (SC: Evo)
Strategy
Custom Maps
External Content
Mutation # 489 Bannable Offense Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies
Brood War
General
ASL20 General Discussion Starcraft at lower levels TvP No Rain in ASL20? Victoria gamers BGH Auto Balance -> http://bghmmr.eu/
Tourneys
Is there English video for group selection for ASL [ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined! Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread Teeworlds - online game General RTS Discussion Thread Nintendo Switch Thread Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Russo-Ukrainian War Thread YouTube Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 759 users

The Big Programming Thread - Page 174

Forum Index > General Forum
Post a Reply
Prev 1 172 173 174 175 176 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
NeMeSiS3
Profile Blog Joined February 2012
Canada2972 Posts
Last Edited: 2012-10-10 21:53:31
October 10 2012 21:46 GMT
#3461
Need help on a question, I just can't understand how to create a test program for my assignment. I created the main program named LineSegment but when trying to make a LineTest file I just stare blankly.

+ Show Spoiler +
In a separate LineTest class, create a test driver that exercises each of the methods in
your LineSegment class, including the accessors for the two endpoints, as well as both
constructors.

Use the following line segments as test data:
Line Segment 1: (0.0, 0.0) to (0.0, 5.0)
Line Segment 2: (2.0, 5.0) to (2.0, 7.0)
Line Segment 3: (1.0, 5.0) to (6.0, 5.0)
Line Segment 4: (2.0, 5.0) to (7.3, 10.1)
Line Segment 5: (0.0, -3.0) to (10.6, 7.2)
Line Segment 6: (0.0, -3.0) to (10.6, 3.0)
Line Segment 7: (2.0, 5.0) to (2.0, 5.0)

For the isParallelTo method, include test cases for each of the following:
• Line segments 1 and 2.
• Line segments 1 and 3.
• Line segments 4 and 5.
• Line segments 4 and 6.
• Line segment 4 compared with itself (yes, this is considered parallel).

For each test case for the isParallelTo method, use an if-else statement in your test
driver to print whether or not the two line segments were found to be parallel. All output
should include enough information so you can identify which line segments are involved
in each test case.

For both the midpoint and length methods, include test cases for each of the
following:
• Line segment 1
• Line segment 3
• Line segment 4
• Line segment 7

It is okay to use the CartesianPoint toString() method for displaying midpoint results.


Code for Cartesian Point

/** Represents a point in a 2D plane, defined as (x,y).
*/
public class CartesianPoint
{

private double x;
private double y;
public CartesianPoint(double xVal, double yVal)
{ x = xVal;
y = yVal;
}

public double getX()
{ return x;
}

public double getY()
{ return y;
}

public double distance (CartesianPoint other)
{ double dx = x - other.x;
double dy = y - other.y;
return Math.sqrt(dx*dx + dy*dy);
}

public String toString()
{ return "CartesianPoint[x=" + x + ", y=" + y + "]";
}
}


Code for LineSegment
public class LineSegment
{
private CartesianPoint point1;
private CartesianPoint point2;

public LineSegment(CartesianPoint pt1,CartesianPoint pt2)
{
point1 = new CartesianPoint(pt1.getX(), pt1.getY());
point2 = new CartesianPoint(pt2.getX(), pt2.getY());
}
public LineSegment(double x1, double x2, double y1, double y2)
{
point1 = new CartesianPoint(x1, y1);
point2 = new CartesianPoint(x2, y2);
}

public CartesianPoint getPoint1()
{ return point1;
}
public CartesianPoint getPoint2()
{ return point2;
}

public boolean isParallelTo(LineSegment line)
{

boolean isParallel = false;
boolean undefined1 = false;
boolean undefined2 = false;
double slope1 = 0;
double slope2 = 0;

if(point1.getX() - point2.getX() == 0)
undefined1 = true;
else
{ slope1 = (point1.getY() - point2.getY()
/ point1.getX() - point2.getX());
}

if(line.getPoint1().getX() - line.getPoint2().getY() == 0)
undefined2 = true;
else
{ slope2 = line.getPoint1().getY() - line.getPoint2().getY()
/ line.getPoint1().getX() - line.getPoint2().getY();
}

if(slope1 == slope2
||
undefined1 == undefined2)

isParallel = true;

return isParallel;
}

public double length()
{
return point1.distance(point2);
}



public CartesianPoint midpoint()
{
double xVar = point1.getX() + point2.getX() / 2;
double yVar = point1.getY() + point2.getY() / 2;

CartesianPoint midpoint = new CartesianPoint(xVar, yVar);
return midpoint;
}
}


I've checked these over, the Cartesian was given (cannot be changed) and my Linesegment compiles and seems to meet all the criteria required I just don't understand how to put it into a test file... My minds like exploding.

EDIT: as a sidenote if you are going to help could you go over the steps etc? I need to learn and even if you just want to give me a start in the right direction that would be perfect, I definitely dont want anyone to do the work for me :D
FoTG fighting!
mcc
Profile Joined October 2010
Czech Republic4646 Posts
Last Edited: 2012-10-10 22:00:09
October 10 2012 21:53 GMT
#3462
On October 11 2012 06:46 NeMeSiS3 wrote:
Need help on a question, I just can't understand how to create a test program for my assignment. I created the main program named LineSegment but when trying to make a LineTest file I just stare blankly.

+ Show Spoiler +
In a separate LineTest class, create a test driver that exercises each of the methods in
your LineSegment class, including the accessors for the two endpoints, as well as both
constructors.

Use the following line segments as test data:
Line Segment 1: (0.0, 0.0) to (0.0, 5.0)
Line Segment 2: (2.0, 5.0) to (2.0, 7.0)
Line Segment 3: (1.0, 5.0) to (6.0, 5.0)
Line Segment 4: (2.0, 5.0) to (7.3, 10.1)
Line Segment 5: (0.0, -3.0) to (10.6, 7.2)
Line Segment 6: (0.0, -3.0) to (10.6, 3.0)
Line Segment 7: (2.0, 5.0) to (2.0, 5.0)

For the isParallelTo method, include test cases for each of the following:
• Line segments 1 and 2.
• Line segments 1 and 3.
• Line segments 4 and 5.
• Line segments 4 and 6.
• Line segment 4 compared with itself (yes, this is considered parallel).

For each test case for the isParallelTo method, use an if-else statement in your test
driver to print whether or not the two line segments were found to be parallel. All output
should include enough information so you can identify which line segments are involved
in each test case.

For both the midpoint and length methods, include test cases for each of the
following:
• Line segment 1
• Line segment 3
• Line segment 4
• Line segment 7

It is okay to use the CartesianPoint toString() method for displaying midpoint results.


Code for Cartesian Point

Show nested quote +
/** Represents a point in a 2D plane, defined as (x,y).
*/
public class CartesianPoint
{

private double x;
private double y;
public CartesianPoint(double xVal, double yVal)
{ x = xVal;
y = yVal;
}

public double getX()
{ return x;
}

public double getY()
{ return y;
}

public double distance (CartesianPoint other)
{ double dx = x - other.x;
double dy = y - other.y;
return Math.sqrt(dx*dx + dy*dy);
}

public String toString()
{ return "CartesianPoint[x=" + x + ", y=" + y + "]";
}
}


Code for LineSegment
Show nested quote +
public class LineSegment
{
private CartesianPoint point1;
private CartesianPoint point2;

public LineSegment(CartesianPoint pt1,CartesianPoint pt2)
{
point1 = new CartesianPoint(pt1.getX(), pt1.getY());
point2 = new CartesianPoint(pt2.getX(), pt2.getY());
}
public LineSegment(double x1, double x2, double y1, double y2)
{
point1 = new CartesianPoint(x1, y1);
point2 = new CartesianPoint(x2, y2);
}

public CartesianPoint getPoint1()
{ return point1;
}
public CartesianPoint getPoint2()
{ return point2;
}

public boolean isParallelTo(LineSegment line)
{

boolean isParallel = false;
boolean undefined1 = false;
boolean undefined2 = false;
double slope1 = 0;
double slope2 = 0;

if(point1.getX() - point2.getX() == 0)
undefined1 = true;
else
{ slope1 = (point1.getY() - point2.getY()
/ point1.getX() - point2.getX());
}

if(line.getPoint1().getX() - line.getPoint2().getY() == 0)
undefined2 = true;
else
{ slope2 = line.getPoint1().getY() - line.getPoint2().getY()
/ line.getPoint1().getX() - line.getPoint2().getY();
}

if(slope1 == slope2
||
undefined1 == undefined2)

isParallel = true;

return isParallel;
}

public double length()
{
return point1.distance(point2);
}



public CartesianPoint midpoint()
{
double xVar = point1.getX() + point2.getX() / 2;
double yVar = point1.getY() + point2.getY() / 2;

CartesianPoint midpoint = new CartesianPoint(xVar, yVar);
return midpoint;
}
}


I've checked these over, the Cartesian was given (cannot be changed) and my Linesegment compiles and seems to meet all the criteria required I just don't understand how to put it into a test file... My minds like exploding.

I can't look at the problem right now, but just glancing. One important rule : Never compare doubles by equality, specifically in this case do not compare double to 0. Use double_var < epsilon, where epsilon is low enough for your needs.

EDIT: As for the test class, just create a class, that somehow acquires test data, then executes the test cases and prints results. Acquiring data can be done in constructor, specialized method or have data hardcoded into the class. Then have some execution method that sequentially calls appropriate methods from your LineSegment class on that data and prints out the result based on return value.
NeMeSiS3
Profile Blog Joined February 2012
Canada2972 Posts
October 10 2012 21:54 GMT
#3463
On October 11 2012 06:53 mcc wrote:
Show nested quote +
On October 11 2012 06:46 NeMeSiS3 wrote:
Need help on a question, I just can't understand how to create a test program for my assignment. I created the main program named LineSegment but when trying to make a LineTest file I just stare blankly.

+ Show Spoiler +
In a separate LineTest class, create a test driver that exercises each of the methods in
your LineSegment class, including the accessors for the two endpoints, as well as both
constructors.

Use the following line segments as test data:
Line Segment 1: (0.0, 0.0) to (0.0, 5.0)
Line Segment 2: (2.0, 5.0) to (2.0, 7.0)
Line Segment 3: (1.0, 5.0) to (6.0, 5.0)
Line Segment 4: (2.0, 5.0) to (7.3, 10.1)
Line Segment 5: (0.0, -3.0) to (10.6, 7.2)
Line Segment 6: (0.0, -3.0) to (10.6, 3.0)
Line Segment 7: (2.0, 5.0) to (2.0, 5.0)

For the isParallelTo method, include test cases for each of the following:
• Line segments 1 and 2.
• Line segments 1 and 3.
• Line segments 4 and 5.
• Line segments 4 and 6.
• Line segment 4 compared with itself (yes, this is considered parallel).

For each test case for the isParallelTo method, use an if-else statement in your test
driver to print whether or not the two line segments were found to be parallel. All output
should include enough information so you can identify which line segments are involved
in each test case.

For both the midpoint and length methods, include test cases for each of the
following:
• Line segment 1
• Line segment 3
• Line segment 4
• Line segment 7

It is okay to use the CartesianPoint toString() method for displaying midpoint results.


Code for Cartesian Point

/** Represents a point in a 2D plane, defined as (x,y).
*/
public class CartesianPoint
{

private double x;
private double y;
public CartesianPoint(double xVal, double yVal)
{ x = xVal;
y = yVal;
}

public double getX()
{ return x;
}

public double getY()
{ return y;
}

public double distance (CartesianPoint other)
{ double dx = x - other.x;
double dy = y - other.y;
return Math.sqrt(dx*dx + dy*dy);
}

public String toString()
{ return "CartesianPoint[x=" + x + ", y=" + y + "]";
}
}


Code for LineSegment
public class LineSegment
{
private CartesianPoint point1;
private CartesianPoint point2;

public LineSegment(CartesianPoint pt1,CartesianPoint pt2)
{
point1 = new CartesianPoint(pt1.getX(), pt1.getY());
point2 = new CartesianPoint(pt2.getX(), pt2.getY());
}
public LineSegment(double x1, double x2, double y1, double y2)
{
point1 = new CartesianPoint(x1, y1);
point2 = new CartesianPoint(x2, y2);
}

public CartesianPoint getPoint1()
{ return point1;
}
public CartesianPoint getPoint2()
{ return point2;
}

public boolean isParallelTo(LineSegment line)
{

boolean isParallel = false;
boolean undefined1 = false;
boolean undefined2 = false;
double slope1 = 0;
double slope2 = 0;

if(point1.getX() - point2.getX() == 0)
undefined1 = true;
else
{ slope1 = (point1.getY() - point2.getY()
/ point1.getX() - point2.getX());
}

if(line.getPoint1().getX() - line.getPoint2().getY() == 0)
undefined2 = true;
else
{ slope2 = line.getPoint1().getY() - line.getPoint2().getY()
/ line.getPoint1().getX() - line.getPoint2().getY();
}

if(slope1 == slope2
||
undefined1 == undefined2)

isParallel = true;

return isParallel;
}

public double length()
{
return point1.distance(point2);
}



public CartesianPoint midpoint()
{
double xVar = point1.getX() + point2.getX() / 2;
double yVar = point1.getY() + point2.getY() / 2;

CartesianPoint midpoint = new CartesianPoint(xVar, yVar);
return midpoint;
}
}


I've checked these over, the Cartesian was given (cannot be changed) and my Linesegment compiles and seems to meet all the criteria required I just don't understand how to put it into a test file... My minds like exploding.

I can't look at the problem right now, but just glancing. One important rule : Never compare doubles by equality, specifically in this case do not compare double to 0. Use double_var < epsilon, where epsilon is low enough for your needs.

I am a first year CS student and this is as much as they've taught us thus far (one month in) so I don't really know how that would work. Sorry I'm green as grass. Thank you though.
FoTG fighting!
mcc
Profile Joined October 2010
Czech Republic4646 Posts
October 10 2012 22:02 GMT
#3464
On October 11 2012 06:54 NeMeSiS3 wrote:
Show nested quote +
On October 11 2012 06:53 mcc wrote:
On October 11 2012 06:46 NeMeSiS3 wrote:
Need help on a question, I just can't understand how to create a test program for my assignment. I created the main program named LineSegment but when trying to make a LineTest file I just stare blankly.

+ Show Spoiler +
In a separate LineTest class, create a test driver that exercises each of the methods in
your LineSegment class, including the accessors for the two endpoints, as well as both
constructors.

Use the following line segments as test data:
Line Segment 1: (0.0, 0.0) to (0.0, 5.0)
Line Segment 2: (2.0, 5.0) to (2.0, 7.0)
Line Segment 3: (1.0, 5.0) to (6.0, 5.0)
Line Segment 4: (2.0, 5.0) to (7.3, 10.1)
Line Segment 5: (0.0, -3.0) to (10.6, 7.2)
Line Segment 6: (0.0, -3.0) to (10.6, 3.0)
Line Segment 7: (2.0, 5.0) to (2.0, 5.0)

For the isParallelTo method, include test cases for each of the following:
• Line segments 1 and 2.
• Line segments 1 and 3.
• Line segments 4 and 5.
• Line segments 4 and 6.
• Line segment 4 compared with itself (yes, this is considered parallel).

For each test case for the isParallelTo method, use an if-else statement in your test
driver to print whether or not the two line segments were found to be parallel. All output
should include enough information so you can identify which line segments are involved
in each test case.

For both the midpoint and length methods, include test cases for each of the
following:
• Line segment 1
• Line segment 3
• Line segment 4
• Line segment 7

It is okay to use the CartesianPoint toString() method for displaying midpoint results.


Code for Cartesian Point

/** Represents a point in a 2D plane, defined as (x,y).
*/
public class CartesianPoint
{

private double x;
private double y;
public CartesianPoint(double xVal, double yVal)
{ x = xVal;
y = yVal;
}

public double getX()
{ return x;
}

public double getY()
{ return y;
}

public double distance (CartesianPoint other)
{ double dx = x - other.x;
double dy = y - other.y;
return Math.sqrt(dx*dx + dy*dy);
}

public String toString()
{ return "CartesianPoint[x=" + x + ", y=" + y + "]";
}
}


Code for LineSegment
public class LineSegment
{
private CartesianPoint point1;
private CartesianPoint point2;

public LineSegment(CartesianPoint pt1,CartesianPoint pt2)
{
point1 = new CartesianPoint(pt1.getX(), pt1.getY());
point2 = new CartesianPoint(pt2.getX(), pt2.getY());
}
public LineSegment(double x1, double x2, double y1, double y2)
{
point1 = new CartesianPoint(x1, y1);
point2 = new CartesianPoint(x2, y2);
}

public CartesianPoint getPoint1()
{ return point1;
}
public CartesianPoint getPoint2()
{ return point2;
}

public boolean isParallelTo(LineSegment line)
{

boolean isParallel = false;
boolean undefined1 = false;
boolean undefined2 = false;
double slope1 = 0;
double slope2 = 0;

if(point1.getX() - point2.getX() == 0)
undefined1 = true;
else
{ slope1 = (point1.getY() - point2.getY()
/ point1.getX() - point2.getX());
}

if(line.getPoint1().getX() - line.getPoint2().getY() == 0)
undefined2 = true;
else
{ slope2 = line.getPoint1().getY() - line.getPoint2().getY()
/ line.getPoint1().getX() - line.getPoint2().getY();
}

if(slope1 == slope2
||
undefined1 == undefined2)

isParallel = true;

return isParallel;
}

public double length()
{
return point1.distance(point2);
}



public CartesianPoint midpoint()
{
double xVar = point1.getX() + point2.getX() / 2;
double yVar = point1.getY() + point2.getY() / 2;

CartesianPoint midpoint = new CartesianPoint(xVar, yVar);
return midpoint;
}
}


I've checked these over, the Cartesian was given (cannot be changed) and my Linesegment compiles and seems to meet all the criteria required I just don't understand how to put it into a test file... My minds like exploding.

I can't look at the problem right now, but just glancing. One important rule : Never compare doubles by equality, specifically in this case do not compare double to 0. Use double_var < epsilon, where epsilon is low enough for your needs.

I am a first year CS student and this is as much as they've taught us thus far (one month in) so I don't really know how that would work. Sorry I'm green as grass. Thank you though.

The reason for that is that you can get screwed over by rounding errors and something that should be 0 will be something like 1e-15, which will fail the test even though it should not.
Kalkom
Profile Joined June 2010
Germany15 Posts
October 10 2012 22:02 GMT
#3465
@NeMeSiS3

Try this : 0.3 == 0.2 + 0.1

Should be true right?
Unfortunately Java will tell you it is false, which has to do with how float numbers are stored in computers. (IEEE 754 for google)
You should instead use something like :

if (value-0.3<0.0001) return true;
else return false;

Hope this clears it up
NeMeSiS3
Profile Blog Joined February 2012
Canada2972 Posts
Last Edited: 2012-10-10 22:29:50
October 10 2012 22:04 GMT
#3466
On October 11 2012 07:02 Kalkom wrote:
@NeMeSiS3

Try this : 0.3 == 0.2 + 0.1

Should be true right?
Unfortunately Java will tell you it is false, which has to do with how float numbers are stored in computers. (IEEE 754 for google)
You should instead use something like :

if (value-0.3<0.0001) return true;
else return false;

Hope this clears it up


My problem was more with writing a testdriver but I will get to editing my boolean statements to make them sharper.

Thanks btw guys

EDIT: For now I'm leaving in the double values as we will eventually learn what you are saying

Code so far (It could be COMPLETELY wrong, this is just how I am interpreting the question, someone feeds in data values (x1, y1, x2. y2) making up a line segment and then I will have to find a way to compare and see parallel, length and midpoint (not at those yet).

import java.util.*;

public class LineTest {
      public static void main(String[] args)
      {
            Scanner var = new Scanner(System.in);
            double x1, x2, y1, y2;

            System.out.println("Please enter a line segment" +
                  "(in the form x1 (enter) x2 (enter) y1 " +
                  "(enter) y2 (enter))");
            x1 = var.nextDouble();
            x2 = var.nextDouble();
            y1 = var.nextDouble();
            y2 = var.nextDouble();


            LineSegment lineSeg1 = new LineSegment(x1, x2, y1, y2);
      }
}
FoTG fighting!
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2012-10-15 00:07:58
October 11 2012 02:07 GMT
#3467
+ Show Spoiler +
In a separate LineTest class, create a test driver that exercises each of the methods in
your LineSegment class, including the accessors for the two endpoints, as well as both
constructors.

Use the following line segments as test data:
Line Segment 1: (0.0, 0.0) to (0.0, 5.0)
Line Segment 2: (2.0, 5.0) to (2.0, 7.0)
Line Segment 3: (1.0, 5.0) to (6.0, 5.0)
Line Segment 4: (2.0, 5.0) to (7.3, 10.1)
Line Segment 5: (0.0, -3.0) to (10.6, 7.2)
Line Segment 6: (0.0, -3.0) to (10.6, 3.0)
Line Segment 7: (2.0, 5.0) to (2.0, 5.0)

For the isParallelTo method, include test cases for each of the following:
• Line segments 1 and 2.
• Line segments 1 and 3.
• Line segments 4 and 5.
• Line segments 4 and 6.
• Line segment 4 compared with itself (yes, this is considered parallel).

For each test case for the isParallelTo method, use an if-else statement in your test
driver to print whether or not the two line segments were found to be parallel. All output
should include enough information so you can identify which line segments are involved
in each test case.

For both the midpoint and length methods, include test cases for each of the
following:
• Line segment 1
• Line segment 3
• Line segment 4
• Line segment 7

It is okay to use the CartesianPoint toString() method for displaying midpoint results.



This is your data.
Line Segment 1: (0.0, 0.0) to (0.0, 5.0)
Line Segment 2: (2.0, 5.0) to (2.0, 7.0)
Line Segment 3: (1.0, 5.0) to (6.0, 5.0)
Line Segment 4: (2.0, 5.0) to (7.3, 10.1)
Line Segment 5: (0.0, -3.0) to (10.6, 7.2)
Line Segment 6: (0.0, -3.0) to (10.6, 3.0)
Line Segment 7: (2.0, 5.0) to (2.0, 5.0)


Run isParallelTo for
• Line segments 1 and 2.
• Line segments 1 and 3.
• Line segments 4 and 5.
• Line segments 4 and 6.
• Line segment 4 and 4.


Run midpoint and length for
• Line segment 1
• Line segment 3
• Line segment 4
• Line segment 7



Create the 7 instances of your LineSegment class with the data.
Then run the functions for each of the test cases above.

For example,

import java.util.*;

public class LineTest {
public static void main(String[] args)
{
// initialize data
LineSegment line1 = new LineSegment(0.0, 0.0, 0.0, 5.0);
LineSegment line2 = new LineSegment(2.0, 5.0, 2.0, 7.0);

// run isParallelTo for line1 and line2
system.out.println(line1.isParallelTo(line2));

// run midpoint and length for line1
system.out.println(line1.midpoint());
system.out.println(line1.length());

}
}



The isParallelTo(LineSegment l) function is incorrect.

slope2 = line.getPoint1().getY() - line.getPoint2().getY() / line.getPoint1().getX() - line.getPoint2().getY(); 


Notice the problem?



I'm not a Java programmer so forgive me if I made a mistake somewhere in syntax.
Other things you should work on though.

• Indenting style. Use Allman's or K&R's, never Horstman's. And don't mix and match them.

• Don't skip braces in if-elsif-else branches unless you only have an if branch. It makes the code annoying to read because if there are errors, you're going to have to check the braces too and this just makes it a hassle.

• Use brackets to strictly enforce your BEDMAS rules.
slope2 = line.getPoint1().getY() - line.getPoint2().getY() / line.getPoint1().getX() - line.getPoint2().getY();

Looks like you want to do (y2/x1) rather than (y1-y2)/(x1-x2). Here's the error in your code by the way. Actually, there's 2.

There is no one like you in the universe.
WhoDoYouThink
Profile Joined July 2010
113 Posts
October 11 2012 02:16 GMT
#3468
I'm wondering if anyone on TeamLiquid is involved in the Zero Robotics competition held by NASA and MIT. StarCraft players have to unite in the alliance stage! :D

Send me a PM if you are involved, doubting anyone responses though

~Rock Rovers

(Zero Robotics is a competition in C to make a sphere - a little cube on the ISS - play a game, autonomously. ONLY HIGH SCHOOLS ARE ALLOWED. I'm a junior.)
I think those IdrAlisks will kill our HuK rays.
PPTouch
Profile Joined January 2011
99 Posts
Last Edited: 2012-10-11 07:30:08
October 11 2012 07:29 GMT
#3469
Hey guys!
My friend needs a bit of help. In his direct words,
"What does a programmer usually want to be paid to program an app that is algorithmed up and ready to go?"
Thanks.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 11 2012 07:31 GMT
#3470
On October 11 2012 16:29 PPTouch wrote:
Hey guys!
My friend needs a bit of help. In his direct words,
"What does a programmer usually want to be paid to program an app that is algorithmed up and ready to go?"
Thanks.


Answer:
"It depends."

What does the app do?
Who is the client?
How many (free) post-launch changes can be expected?
PPTouch
Profile Joined January 2011
99 Posts
October 11 2012 07:38 GMT
#3471
On October 11 2012 16:31 Morfildur wrote:
Show nested quote +
On October 11 2012 16:29 PPTouch wrote:
Hey guys!
My friend needs a bit of help. In his direct words,
"What does a programmer usually want to be paid to program an app that is algorithmed up and ready to go?"
Thanks.


Answer:
"It depends."

What does the app do?
Who is the client?
How many (free) post-launch changes can be expected?

Thanks! Do you mind if I PM you once I attain this information?
FFGenerations
Profile Blog Joined April 2011
7088 Posts
Last Edited: 2012-10-12 21:36:48
October 12 2012 21:35 GMT
#3472
hihi, i am trying to do something very simple. it is like my 2nd class so we havent covered much at all.
+ Show Spoiler +


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
float n;
float n1;

cout<<"Enter numbers. Press '0' to end."<<endl;

do
{
cin>>n;

n1=n1+n;

}

while (n!=0);

cout<<"Okay! The total sum of your numbers is "<<n1<<endl;


system("PAUSE");
}



however i want to make the button to quit the loop to be 'g' rather than '0' ie a char/long. i tried making it into If or Switch and that didnt seem to work, and i tried looking at making a Do..While or While inside the Do...While... that didnt seem to work. so i realised it was probably something u can do with validation which we touched on for a split second..

but i cant get anything to work and dont want to jump ahead doing stuff with copy paste im unable to understand

we have a worksheet with an example of atoi validation which would make it look something like..

+ Show Spoiler +


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
char exit[256];
double n1;
double n;

cout<<"Enter numbers. '0' to end."<<endl;

do
{
gets (exit);
n=atoi(exit);

n1+=n;
}

while (exit!="0");

cout<<"ending"<<endl;
cout<<n1;

system("PAUSE");
}

//while (!((cin >> n).rdstate() & ifstream::failbit)) { n2 += n; }



someone online suggested trying strcmp and strtol but i dont know how to use those (was messing around and couldnt get much out of it at least) . really if there is a simpler way then i should stick to that because we will probably be covering it in class soonish...

+ Show Spoiler +


#include <cstdlib>
#include <iostream>
#include <string.h>

using namespace std;

int main(int argc, char *argv[])
{
int n;
int n1;
char exit[256];


cout<<"Enter numbers. 'g' to end."<<endl;
//while(0 != strcmp(stringsx,"g"))
do
{
cin>>exit;

n1+=n;
}

while (1 != strcmp(exit,"g"));

cout<<"ending"<<endl;
cout<<n1;

system("PAUSE");
}

//while (!((cin >> n).rdstate() & ifstream::failbit)) { n2 += n; }



the other thing in the bottom of the code is something someone suggested but i asked for something simpler so ignored that so far
Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-10-12 22:17:21
October 12 2012 22:09 GMT
#3473
On October 13 2012 06:35 FFGenerations wrote:
however i want to make the button to quit the loop to be 'g' rather than '0'

Then do something like this:
do
{
char input;
cin >> input;

// optionally if you include <stdio.h>
getchar( &input );
} while(input != 'g');


Floats take up 4 bytes of memory. If you don't know what a byte is, try looking it up. A character takes only a single byte. If you are trying to grab a float out of cin (your n variable is a float) it will be looking for something that it can interpret as a float, i.e. a number. You won't be able to convert a float to the character 'g' very easily. This is because the bit format for a float is very different from that of a character.

So, you use cin and extract a single character, which grabs the next 8 bits from the standard in stream (cin). If you aren't familiar with the difference between ' ' and " " in C and C++, then read the spoiler:
+ Show Spoiler +
Using the ' ' will generate a character literal, as in a single byte long character. 'a' is actually an integer, as characters are unsigned integers ranging from 0 to 255. 'a' represents the number 96. You can actually do 10 + 'a' and have valid code. 10 + 'a' is 106, or 'j'.

" " creates a string literal, as in an array of characters. " " takes whatever is inside the two brackets and creates an array of characters with the characters between the two quotes, and places the character representing the number 0 at the end. This represents a string in C. An array of characters with a null character ( 0 ) at the end is a string. So, using "sadf" returns a character array that represents a string, which looks like this:
"sadf" // equivalent to the following:
{ 's', 'a', 'd', 'f', '/0' }


Edit: I also don't like seeing everyone do "using namespace std;". I guess it's okay if this is only your second class, but really you should be fully understanding what a namespace is, what using means, and what std is. When you write cin you should be manually accessing the std namespace with the :: operator. The using operator clutters your global namespace. I'm just not a fan of using things you don't understand.
do
{
char input;
std::cin >> input;

// optionally if you include <stdio.h>
getchar( &input );
} while(input != 'g');
dapierow
Profile Blog Joined April 2010
Serbia1316 Posts
October 13 2012 03:18 GMT
#3474
Hey guys im creating a currency webpage with php and I have a question on how to do the conversion calculation

This is my code so far


<?php

$aExchangeRates = array
(
'USD' => 1.00000
'AUD' => 0.95593
'BPL' => 0.49418
'CAD' => 0.97645
'CNY' => 6.30662
'EUR' => 0.77045
'GBP' => 0.61616
'JPY' => 78.1850
'INR' => 53.3650
'NZD' => 1.20642
'RUB' => 31.0310
);

$amount = $_POST['amount'];
$from = $_POST['from'];
$to = $_POST['to'];

echo " " . $amount . " " . $from . " Converts to " . $to . " ";
?>



I get the amount, to and from, from a textfield, drop down and another dropdown, and ideas how can i can fit in the array to compute the currencies?
Eat.Sleep.Starcraft 2
tofucake
Profile Blog Joined October 2009
Hyrule19083 Posts
Last Edited: 2012-10-13 04:09:30
October 13 2012 04:09 GMT
#3475
	$amount = $amount;
$from = $amount * $aExchangeRates['USD'];
$to = $from * $aExchangeRates[$_POST['to']];

echo " $amount from {$_POST['from']} converts to \$$to {$_POST['to']} ";

something like that I guess
completely untested
Liquipediaasante sana squash banana
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2012-10-13 11:54:31
October 13 2012 11:43 GMT
#3476
On October 13 2012 12:18 dapierow wrote:
Hey guys im creating a currency webpage with php and I have a question on how to do the conversion calculation

This is my code so far


<?php

$aExchangeRates = array
(
'USD' => 1.00000
'AUD' => 0.95593
'BPL' => 0.49418
'CAD' => 0.97645
'CNY' => 6.30662
'EUR' => 0.77045
'GBP' => 0.61616
'JPY' => 78.1850
'INR' => 53.3650
'NZD' => 1.20642
'RUB' => 31.0310
);

$amount = $_POST['amount'];
$from = $_POST['from'];
$to = $_POST['to'];

echo " " . $amount . " " . $from . " Converts to " . $to . " ";
?>



I get the amount, to and from, from a textfield, drop down and another dropdown, and ideas how can i can fit in the array to compute the currencies?


Are you doing this as a proof of concept or for real work. If the latter why not use a service like google calculator?

Example way of using google calculator

If it is a proof of concept, I'm guessing all those exchange rates are in relation to USD ? So you would have to convert everything to USD and then convert that result to your target currency.

From currency X to currency Y with value V going through USD -> ( V / exchangeRate(X) ) * exchangeRate(Y)

TheManInBlack
Profile Blog Joined December 2011
Nigeria266 Posts
October 13 2012 19:05 GMT
#3477
I just started using Python 2.7.3

The package comes with an IDLE Python GUI (which comes with a run Module option in the shell) and a Python Command line.

Now I write my programs in the GUI, but how do I run them from the command line? Because some of the practice code I am writing have prompts such as 'if x < 1, print " "', meaning the user must type in a value for the program to continue.

But I can't get the thing to work.

Does the command line have a code editor or is there something I am missing?
Ilikestarcraft
Profile Blog Joined November 2004
Korea (South)17727 Posts
Last Edited: 2012-10-13 21:04:17
October 13 2012 20:25 GMT
#3478
http://cli.learncodethehardway.org/book/
http://learnpythonthehardway.org/book/ex0.html
Here are 2 links for my info.

The cli doesn't have a code editor. You write your code in a separate text editor and save it. Then you open your cli (powershell assuming windows) and change folders (type "cd name" to do so) into where your code was saved through the cli. When you're at the right folder in the cli, run your program from it (type "python name.py"). I'll assume you know that name is the name of the folder and the file. One thing is that you might write "cd name" and the name you type is the folder your code is in itself. It won't work like that. First type "pwd" and that will print the current directory/folder you are in. Then type "ls" that will list the folders/files in the directory you are in. Then you change into the folder which contains the folder where your code is saved like "My Documents". And you keep changing till you reach it.
"Nana is a goddess. Or at very least, Nana is my goddess." - KazeHydra
phar
Profile Joined August 2011
United States1080 Posts
October 13 2012 23:05 GMT
#3479
On October 11 2012 07:04 NeMeSiS3 wrote:My problem was more with writing a testdriver

Blisse's post above will work, and it can definitely help you out. Pay attention to most of his points about style - it'll definitely help the next time you have to ask someone else for assistance (much easier to read well-formatted code).

However, I would suggest using a Unit Test instead of writing a binary class - JUnit is your friend. In fact, if you're using Eclipse, this could probably be built in.

Additionally, when you compare doubles, make sure to take the absolute value of the difference, instead of doing just (Expected - Actual) < epsilon. Even better, if you use a unit test, simply write

assertEquals(expected, actual, epsilon) - if your variables are doubles, TestCase.assertEquals will take care of the rest of it for you.

More info on java unit tests: http://www.vogella.com/articles/JUnit/article.html
Who after all is today speaking about the destruction of the Armenians?
NeMeSiS3
Profile Blog Joined February 2012
Canada2972 Posts
October 13 2012 23:14 GMT
#3480
So I just got my lineup for the midterm
+ Show Spoiler +

1. Write a "standard" java class.

//Instance variables
//Constructors
//Methods
--Accessor (getters)
--Mutator (setters)

2. "Has a" relationships

3. If Statements (easy pzy)

4. Understanding object reference variables
EX:
CP pt1 = new CP(1,2);
CP pt2 = new CP(3,4);
pt1 = pt2;
pt1.setX(5);
pt2.getX();

What is going to be presented? (ASSUME*** all previous code is in place to make such functions able to process)



My question is how should I study for this? It seems like a silly question but we never really got any questions all year, we just ran examples and did assignments and as this is my first year in CS I just dunno what it'll look like. Any advice or help on these, anyone got a simple way to remember "class" creation/use. I always have a bitch of a time writing multiple classes.

thanks!
FoTG fighting!
Prev 1 172 173 174 175 176 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 1h 5m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech79
trigger 10
StarCraft: Brood War
ggaemo 244
Leta 230
Zeus 162
Pusan 92
PianO 91
sSak 81
ToSsGirL 55
Bisu 54
JulyZerg 35
Sacsri 33
[ Show more ]
sorry 31
NaDa 29
ajuk12(nOOB) 29
Shine 28
Noble 19
yabsab 17
Hm[arnc] 13
scan(afreeca) 11
Bale 7
Liquid`Ret 6
Sharp 1
Dota 2
BananaSlamJamma204
XcaliburYe128
Fuzer 118
Counter-Strike
Stewie2K862
olofmeister846
shoxiejesuss522
Other Games
singsing927
ceh9551
JimRising 278
Happy165
Mew2King101
OGKoka 83
NeuroSwarm48
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• Berry_CruncH55
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt845
Upcoming Events
Sparkling Tuna Cup
1h 5m
PiGosaur Monday
15h 5m
LiuLi Cup
1d 2h
Replay Cast
1d 15h
The PondCast
2 days
RSL Revival
2 days
Maru vs SHIN
MaNa vs MaxPax
OSC
2 days
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
3 days
Reynor vs Astrea
Classic vs sOs
BSL Team Wars
3 days
Team Bonyth vs Team Dewalt
CranKy Ducklings
4 days
[ Show More ]
RSL Revival
4 days
GuMiho vs Cham
ByuN vs TriGGeR
Cosmonarchy
4 days
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
[BSL 2025] Weekly
4 days
RSL Revival
5 days
Cure vs Bunny
Creator vs Zoun
BSL Team Wars
5 days
Team Hawk vs Team Sziky
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

CSL Season 18: Qualifier 2
SEL Season 2 Championship
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL 2025 AUTUMN (S18)
Maestros of the Game
Sisters' Call Cup
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

LASL Season 20
2025 Chongqing Offline CUP
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
EC S1
BLAST Rivals Fall 2025
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
MESA Nomadic Masters Fall
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.