• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:59
CET 03:59
KST 11:59
  • 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
[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy5ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289
Community News
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool38Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12Blizzard Classic Cup - Tastosis announced as captains18
StarCraft 2
General
Potential Updates Coming to the SC2 CN Server Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Weekly Cups (March 2-8): ByuN overcomes PvT block Weekly Cups (August 25-31): Clem's Last Straw? Weekly Cups (March 9-15): herO, Clem, ByuN win
Tourneys
World University TeamLeague (500$+) | Signups Open RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament WardiTV Team League Season 10 KSL Week 87
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026]
External Content
Mutation # 518 Radiation Zone The PondCast: SC2 News & Results Mutation # 517 Distant Threat Mutation # 516 Specter of Death
Brood War
General
Soulkey's decision to leave C9 JaeDong's form before ASL BGH Auto Balance -> http://bghmmr.eu/ [ASL21] Ro24 Preview Pt1: New Chaos ASL21 General Discussion
Tourneys
[Megathread] Daily Proleagues ASL Season 21 LIVESTREAM with English Commentary [BSL22] Open Qualifiers & Ladder Tours Small VOD Thread 2.0
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine YouTube Thread Canadian Politics Mega-thread Russo-Ukrainian War Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Movie Discussion! [Req][Books] Good Fantasy/SciFi books [Manga] One Piece
Sports
2024 - 2026 Football Thread Cricket [SPORT] Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 5852 users

The Big Programming Thread - Page 174

Forum Index > General Forum
Post a Reply
Prev 1 172 173 174 175 176 1032 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
Hyrule19196 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)17733 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.
ils
"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 1032 Next
Please log in or register to reply.
Live Events Refresh
The PiG Daily
21:20
Best Games
Solar vs Cure
herO vs TBD
LiquipediaDiscussion
PSISTORM Gaming Misc
20:00
FSL showmatch Nachoz vs all
Liquipedia
LAN Event
16:00
StarCraft Madness Day 2
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft445
RuFF_SC2 208
Nathanias 203
StarCraft: Brood War
GuemChi 5661
Artosis 719
Noble 30
NaDa 30
Bale 14
Dota 2
monkeys_forever654
LuMiX2
League of Legends
JimRising 732
Other Games
summit1g11933
Maynarde147
ViBE144
Mew2King109
UpATreeSC41
JuggernautJason12
deth10
Temp03
Organizations
Other Games
gamesdonequick925
Dota 2
PGL Dota 2 - Main Stream73
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Hupsaiya 185
• davetesta22
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki18
• RayReign 14
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo223
Upcoming Events
Replay Cast
6h 1m
Afreeca Starleague
7h 1m
Sharp vs Scan
Rain vs Mong
Wardi Open
9h 1m
Monday Night Weeklies
14h 1m
Sparkling Tuna Cup
1d 7h
Afreeca Starleague
1d 7h
Soulkey vs Ample
JyJ vs sSak
Replay Cast
2 days
Afreeca Starleague
2 days
hero vs YSC
Larva vs Shine
Kung Fu Cup
2 days
Replay Cast
2 days
[ Show More ]
KCM Race Survival
3 days
The PondCast
3 days
WardiTV Team League
3 days
Replay Cast
3 days
WardiTV Team League
4 days
RSL Revival
5 days
Cure vs Zoun
herO vs Rogue
WardiTV Team League
5 days
Platinum Heroes Events
5 days
BSL
5 days
RSL Revival
6 days
ByuN vs Maru
MaxPax vs TriGGeR
WardiTV Team League
6 days
BSL
6 days
Liquipedia Results

Completed

Proleague 2026-03-22
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
BSL Season 22
CSL Elite League 2026
CSL Season 20: Qualifier 1
ASL Season 21
Acropolis #4 - TS6
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

2026 Changsha Offline CUP
CSL Season 20: Qualifier 2
CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
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 © 2026 TLnet. All Rights Reserved.