• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 10:21
CET 16:21
KST 00:21
  • 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
Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3
Community News
Starcraft, SC2, HoTS, WC3, returning to Blizzcon!13$5,000+ WardiTV 2025 Championship4[BSL21] RO32 Group Stage3Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win9
StarCraft 2
General
Starcraft, SC2, HoTS, WC3, returning to Blizzcon! RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win 5.0.15 Patch Balance Hotfix (2025-10-8) TL.net Map Contest #21: Voting
Tourneys
Constellation Cup - Main Event - Stellar Fest Merivale 8 Open - LAN - Stellar Fest $5,000+ WardiTV 2025 Championship Sea Duckling Open (Global, Bronze-Diamond) $3,500 WardiTV Korean Royale S4
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review [BSL21] RO32 Group Stage Practice Partners (Official) [ASL20] Ask the mapmakers — Drop your questions
Tourneys
BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION [ASL20] Grand Finals Small VOD Thread 2.0 The Casual Games of the Week Thread
Strategy
Current Meta How to stay on top of macro? PvZ map balance Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Dawn of War IV ZeroSpace Megathread General RTS Discussion Thread
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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Career Paths and Skills for …
TrAiDoS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1781 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
Hyrule19150 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)17731 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 1032 Next
Please log in or register to reply.
Live Events Refresh
LAN Event
15:00
Day 3: Ursa 2v2, FFA
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 320
StarCraft: Brood War
Mini 1668
Sea 1095
GuemChi 933
Jaedong 707
Stork 688
firebathero 583
Soma 528
Shuttle 257
Rush 249
hero 217
[ Show more ]
sSak 165
Leta 153
Hyuk 128
Soulkey 125
Barracks 118
Hyun 86
Mong 85
Sharp 76
Pusan 61
Backho 54
Snow 53
Sea.KH 53
ToSsGirL 40
sas.Sziky 28
Shine 17
Movie 17
Terrorterran 14
Yoon 14
scan(afreeca) 13
IntoTheRainbow 10
Noble 5
Dota 2
qojqva2629
Dendi724
Other Games
singsing2233
B2W.Neo675
hiko581
DeMusliM485
Lowko350
crisheroes319
Mlord264
Fuzer 259
ArmadaUGS145
XaKoH 106
XcaliburYe83
Mew2King53
QueenE48
Organizations
Counter-Strike
PGL149
StarCraft: Brood War
Kim Chul Min (afreeca) 7
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 31
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV462
League of Legends
• Jankos2056
• TFBlade501
Upcoming Events
OSC
6h 40m
Replay Cast
7h 40m
OSC
20h 40m
LAN Event
23h 40m
Korean StarCraft League
1d 11h
CranKy Ducklings
1d 18h
LAN Event
1d 23h
IPSL
2 days
dxtr13 vs OldBoy
Napoleon vs Doodle
BSL 21
2 days
Gosudark vs Kyrie
Gypsy vs Sterling
UltrA vs Radley
Dandy vs Ptak
Replay Cast
2 days
[ Show More ]
Sparkling Tuna Cup
2 days
WardiTV Korean Royale
2 days
LAN Event
2 days
IPSL
3 days
JDConan vs WIZARD
WolFix vs Cross
BSL 21
3 days
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
3 days
Wardi Open
3 days
WardiTV Korean Royale
4 days
Replay Cast
5 days
Kung Fu Cup
5 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
6 days
The PondCast
6 days
RSL Revival
6 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
6 days
WardiTV Korean Royale
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025

Upcoming

BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals 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.