• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 16:20
CEST 22:20
KST 05:20
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL49Weekly Cups (June 23-29): Reynor in world title form?12FEL Cracov 2025 (July 27) - $8000 live event16Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Esports World Cup 2025 - Final Player Roster How does the number of casters affect your enjoyment of esports? Weekly Cups (June 23-29): Reynor in world title form?
Tourneys
RSL: Revival, a new crowdfunded tournament series [GSL 2025] Code S: Season 2 - Semi Finals & Finals $5,100+ SEL Season 2 Championship (SC: Evo) FEL Cracov 2025 (July 27) - $8000 live event HomeStory Cup 27 (June 27-29)
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
Flash Announces Hiatus From ASL [ASL19] Finals Recap: Standing Tall BGH Auto Balance -> http://bghmmr.eu/ Player “Jedi” cheat on CSL Help: rep cant save
Tourneys
Small VOD Thread 2.0 [Megathread] Daily Proleagues [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
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 Russo-Ukrainian War Thread Trading/Investing Thread The Games Industry And ATVI
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread NBA General Discussion Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 665 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
Hyrule19029 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)17726 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 3h 40m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 596
JuggernautJason94
StarCraft: Brood War
Britney 14479
Dewaltoss 192
Aegong 45
GoRush 13
IntoTheRainbow 7
yabsab 5
Dota 2
Gorgc7367
League of Legends
Dendi1481
JimRising 443
Counter-Strike
fl0m1928
flusha408
Foxcn365
sgares185
Super Smash Bros
Mew2King179
Heroes of the Storm
Liquid`Hasu605
Other Games
summit1g6033
FrodaN2371
tarik_tv1112
elazer248
RotterdaM161
Pyrionflax116
ViBE84
Trikslyr64
Sick62
PPMD12
Liquid`Ken5
Organizations
Other Games
BasetradeTV30
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• LUISG 10
• intothetv
• IndyKCrew
• sooper7s
• Migwel
• AfreecaTV YouTube
• LaughNgamezSOOP
• Kozan
StarCraft: Brood War
• blackmanpl 38
• 80smullet 29
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Doublelift2783
• Jankos2203
• masondota2502
Other Games
• imaqtpie873
• Shiphtur187
Upcoming Events
Replay Cast
3h 40m
RSL Revival
13h 40m
herO vs SHIN
Reynor vs Cure
OSC
16h 40m
WardiTV European League
19h 40m
Scarlett vs Percival
Jumy vs ArT
YoungYakov vs Shameless
uThermal vs Fjant
Nicoract vs goblin
Harstem vs Gerald
FEL
19h 40m
Korean StarCraft League
1d 6h
CranKy Ducklings
1d 13h
RSL Revival
1d 13h
FEL
1d 19h
Sparkling Tuna Cup
2 days
[ Show More ]
RSL Revival
2 days
FEL
2 days
BSL: ProLeague
2 days
Dewalt vs Bonyth
Replay Cast
4 days
Replay Cast
4 days
The PondCast
5 days
Replay Cast
6 days
RSL Revival
6 days
Liquipedia Results

Completed

Proleague 2025-06-28
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025
YaLLa Compass Qatar 2025

Upcoming

CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #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 © 2025 TLnet. All Rights Reserved.