keep getting decimal answers for the change and it need to be whole numbers. import
Question:
keep getting decimal answers for the change and it need to be whole numbers.
import java.util.Scanner ;
public class pirates
{
static final double Genuine_PieceofEight = 8;
static final double PirateHat = 32;
static final double EyePatch = 1;
static final double Sword= 20;
static final double TreasureMap=100;
static final double Teeshirt= 150;
static int numberGenuinePieceofEight;
static int numberPirateHat;
static int numberEyePatch;
static int numberSword;
static int numberTreasureMap;
static int numberTeeshirt;
public static void main(String[] args) {
double GenuinePieceofEight =0;
Scanner input = new Scanner(System.in);
System.out.println("How many Pieces of Eight do you want?");
String numberShirts = input.nextLine();
System.out.println("How many Pirate Hats?");
String numberChips = input.nextLine();
System.out.println("How many eye patches?");
numberEyePatch = input.nextInt();
System.out.println("How many swords do you need?");
String numberSwords=input.nextLine();
System.out.println("How many treasure maps will you need?");
numberTreasureMap=input.nextInt();
System.out.println("How many tee shirts will you need?");
numberTeeshirt= input.nextInt();
GenuinePieceofEight = GenuinePieceofEight * numberGenuinePieceofEight;
double Piratehat = PirateHat*numberPirateHat;
double Eyepatch = EyePatch*numberEyePatch;
double sword= Sword*numberSword;
double treasureMap=TreasureMap*numberTreasureMap;
double teeshirt=Teeshirt*numberTeeshirt;
double finalTotal = GenuinePieceofEight + Piratehat + Eyepatch+sword+treasureMap+teeshirt;;
System.out.println("Your total is: " + finalTotal +"BITS");
{
System.out.println("How many Bits was your items?");
int inputBits = input.nextInt();
System.out.println("How man gold doubloons have ye got?");
int inputDoubloons = input.nextInt();
// Lable exchanges
final int DOUBLOON = 128;
final int PISTOLE = 32;
final int Pe = 8;
final int BIT = 1;
// Declare they are numbers COUNT of coins
double numBits, numPistole, numPe, numDoubloon;
// Calculations % is remander (thank you textbook)
// value of coins and count
int userdblvalue;
userdblvalue = inputDoubloons * DOUBLOON;
double change= finalTotal - userdblvalue;
change = userdblvalue - inputBits;
numDoubloon = change / DOUBLOON; // count of doubloons
change = change % DOUBLOON; // change left
numPistole = change / PISTOLE; // count of pistole
change = change % PISTOLE; // change left
numPe = change / Pe;// count of Pe
change = change % Pe;// change
numBits = change; // number of bits
// Give change equivilant.
System.out.println("Yer change is:");
// else if statements to print correct
if (numBits == 1) {
System.out.println(numBits + BIT);
}
else if (numBits == 0) {
System.out.println();
} else {
System.out.println(numBits + " Bits");
}
if (numPe == 1) {
System.out.println(numPe + "Piece Of Eight");
} else if (numPe == 0) {
System.out.println();
} else {
System.out.println(numPe + "Pieces Of Eight");
}
if (numPistole == 1) {
System.out.println(numPistole + "Pistole");
} else if (numPistole == 0) {
System.out.println();
} else {
System.out.println(numPistole + " Pistoles");
}
if (numDoubloon == 1) {
System.out.println(numDoubloon + "Doubloon");
} else if (numDoubloon == 0) {
System.out.println();
} else {
System.out.println(numPe + "Doubloons");
}
// Print out last line
System.out.println("Now shove off before I make ye walk the plank!");
}
}
}
Managing Business Ethics Making Ethical Decisions
ISBN: 9781506388595
1st Edition
Authors: Alfred A. Marcus, Timothy J. Hargrave