Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created Planet Express using Java #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions planetExpress/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package planetExpress;
import java.util.Scanner;
public class Game {

public static void main(String[] args)
{
PlanetExpress planet;
Score score;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I wasn't sure if I like the Score class in the Game, or if it would make more sense to be in the PlanetExpress class. I think that after some thought this makes sense to be in the Game because then you could have a separate PlanetExpress instance that wasn't so much a game, but just a separate class.

Boolean stable = true;

planet = new PlanetExpress();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are not going to use the undeclared variable anywhere, I would recommend doing the declaration (PlanetExpress planet) and the assignment = new PlanetExpress() all on one line

score = new Score();
Scanner reader = new Scanner(System.in);


while (stable = true)
{
System.out.println("Choose what do you want to do next:");
System.out.println("press \"1\" if you want to deliver");
System.out.println("press \"2\" if you want to steal");
System.out.println("press \"3\" if you want to eat");
System.out.println("press \"4\" if you want to drink");
System.out.println("press \"5\" if you want to account");
int step = reader.nextInt();

switch(step)
{
case '1' :

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the value is an integer, I don't think you need '1', I think you can just use plain old 1

planet.deliver();
case '2' :
planet.steal();
case '3' :
planet.eat();
case '4' :
planet.drink();
case '5' :
planet.account();
default :

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! You always want to use a default in your case statements

System.out.println("Invalid number");
}

score.setScore(planet.getThirst(), planet.getWork(), planet.getHorde(), planet.getHunger(), planet.getReceipts());
if (planet.check() == false)
{
stable = false;
}
}
}

}
109 changes: 109 additions & 0 deletions planetExpress/PlanetExpress.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package planetExpress;

public class PlanetExpress {

private int thirst;
private int work;
private int horde;
private int hunger;
private int receipts;
private boolean stable;

public PlanetExpress() {
thirst = 50;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a constant for these values

work = 50;
horde = 50;
hunger = 50;
receipts = 50;
stable = true;
}

public int getThirst()
{
return thirst;
}

public int getWork()
{
return thirst;
}

public int getHorde()
{
return thirst;
}

public int getHunger()
{
return thirst;
}

public int getReceipts()
{
return thirst;
}

public void drink()
{
thirst -= 10;
work += 10;
}

public void deliver()
{
work -= 10;
receipts += 10;
}

public void steal()
{
horde += 10;
work += 10;
}

public void eat()
{
hunger -= 10;
work += 10;
}

public void account()
{
receipts -= 10;
horde -= 10;
}

public boolean check()
{
if ((this.thirst > 80) || (this.work > 80) || (this.hunger > 80) || (this.horde < 20) || (this.receipts < 20))
{
this.stable = false;
return false;
}
else
{
if(this.thirst > 70)
{
System.out.println("You should drink more");
}
if(this.work > 70)
{
System.out.println("You have too much work to do");
}
if(this.hunger > 70)
{
System.out.println("You need to eat something");
}
if(this.horde < 30)
{
System.out.println("The horde is too low");
}
if(this.receipts < 30)
{
System.out.println("The receipts are too low");
}
}
return true;
}

}
31 changes: 31 additions & 0 deletions planetExpress/Score.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package planetExpress;

public class Score {
float score;

public Score() {
score = 0;
}

private float checkLow(int num)
{
return (((100 - num) * 2) / 10);
}

private float checkHigh(int num)
{
return ((num * 2) / 10);
}

public float setScore (int thirst, int work, int horde, int hunger, int receipts)
{
this.score = checkLow(thirst) + checkLow(work) + checkLow(hunger) + checkHigh(horde) + checkHigh(receipts);
return this.score;
}

public float getScore ()
{
return this.score;
}

}