Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java code change mistake -------------------------- i use word in here: private static int current_fund ; private static int initial_fund ; private static int number_of_nights ;

java code

change mistake

--------------------------

i use word in here:

private static int current_fund;

private static int initial_fund;

private static int number_of_nights;

private static int number_of_nights_wo_money_t = 0;

private static int number_of_nights_wo_money = 0;

private static String current_city;

private static String current_jouranal;

private boolean started = true;

private int current_city_cost;

private static int paris_postcard_cost = 4;

public static final int SYMPATHY_FACTOR = 30;

private static int total_cards ;

------------------------

miktake 1

image text in transcribed

code:

image text in transcribed

image text in transcribed

require:

image text in transcribed

image text in transcribed

mistake 2:

image text in transcribed

code:

image text in transcribed

test:

image text in transcribed

require;

image text in transcribed

mistakte 3:

image text in transcribed

paris(start), city(1),city(2),city(3),....city(10).

image text in transcribed

code

image text in transcribed

require

image text in transcribed

test

image text in transcribed

test code in here:

// a few cities to visit

City paris = new City("Paris", 75);

City rome = new City("Rome", 50);

// start out in Pairs

Backpacker t = new Backpacker(500, paris);

// initial states

System.out.println(t.getCurrentCity()); // expected "pairs"

System.out.println(t.getJournal()); // expect "Pairs(starts), Rome(2)"

// back to Pairs for a week

t.visit(paris, 7); //expected "Pairs"

System.out.println(t.getCurrentCity());// "Pairs(start),Rome(2),Pairs(7)"

t = new Backpacker(500, paris); //start over

// initial state

System.out.println(t.getCurrentMoney()); // expected 500

t.visit(rome, 2); System.out.println(t.getCurrentMoney()); // expected 400

t.visit(paris, 7); System.out.println(t.getCurrentMoney()); // expected 25

System.out.println(t.getNightsInStation()); // expected 2

t.visit(paris, 7);

System.out.println(t.getCurrentMoney()); // expected 25

System.out.println(t.getNightsInStation()); // expected 9

t.sendPostcardsHome(1);

System.out.println(t.getCurrentMoney()); // expected 21

t.sendPostcardsHome(12);

System.out.println(t.getCurrentFunds()); // expected 1

System.out.println(t.isSOL()); // expected true

t.callHomeForMoney();

System.out.println(t.getCurrentMoney()); // expected 181

t.callHomeForMoney();

System.out.println(t.getCurrentMoney()); // still just 181

}

}

PROBLEM: Message: For new Backpacker (25, Paris/75), after 1 postcard, then call HomeForMoney, getCurrentMoney should return 51. expected: but was: PROBLEM: Message: For new Backpacker (25, Paris/75), after 6 postcards, then call HomeForMoney, getCurrentMoney should return 181. expected: but was: PROBLEM: Message: For new Backpacker (25, Paris/75), after 1 postcard, then callHomeForMoney twice, getCurrentMoney should return 51. expected: but was: PROBLEM: Message: For new Backpacker (25, Barcelona/45), after send 3 postcards from Barcelona 45, 1 from Paris/75, 2 from Barcelona 45, 5 from Paris/75, then callHomeForMoney. getCurrentMoney should return 243. expected: but was: public void callHomeForMoney () { //Money from home is n time ( no of cards) * sypmathy factor. int home_money = total_cards * SYMPATHY_FACTOR; current fund = current fund + home_money public void sendPostcardsHome(int howMany) { if (current city == "Paris") { int cost = paris_postcard_cost * howMany; int max_cards = current_fund / paris_postcard_cost; if (max_cards but was: PROBLEM: Message: For new Backpacker (25, Barcelona/45), after send 3 postcards from Barcelona 45, 1 from Paris/75, 2 from Barcelona/45, 5 from Paris/75, getCurrentMoney should return 3. expected: but was: PROBLEM: Message: For new Backpacker 25, Paris/75), after 1 postcard, then callHomeForMoney, getCurrentMoney should return 51. expected: but was: PROBLEM: Message: For new Backpacker (25, Paris/75), after 6 postcards, then callHomeForMoney, getCurrentMoney should return 181. expected: but was: PROBLEM: Message: For new Backpacker (25, Paris/75), after 1 postcard, then callHomeForMoney twice, getCurrentMoney should return 51. expected: but was: PROBLEM: Message: For new Backpacker (25, Barcelona/45), after send 3 postcards from Barcelona 45, 1 from Paris/75, 2 from Barcelona/45, 5 from Paris/75, then callHomeForMoney, getCurrentMoney should return 243. expected: but was: public int getCurrentMoney () { if (current_city == "London") { current_city_cost = current_fund - (200 * 3); if (current_city == "Paris"){ current_city_cost = current_fund -(75 * 7); } if (current_city == "Prague") { current_city_cost = current_fund -(7 *12); if (current_city == "Barcelona") { current_city_cost = current_fund 7 45; return current_fund; public String getCurrentCity () Returns the name of the Backpacker's current city. public int getCurrentMoney () Returns the amount of money the Backpacker currently has. Next, what happens to the funds if we follow the same itinerary as above? For Rome, we can determine (from the City object) that we have enough money for 10 nights. We're staying 2 nights, which is less than 10, so we buy lodging for 2 nights. That costs 2 * 50, or 100 euros, so we expect to have 400 left. t = new Backpacker (500, paris); 1/ start over // initial state System.out.println(t.getCurrentMoney ()); // expected 500 // visit a city t.visit(rome, 2); System.out.println(t.getCurrentMoney ()); // expected 400 When we go back to Paris for a week, it's a bit different. We determine (from the City object) that 400 euros is enough for only 5 nights. The desired number is 7 nights, and the smaller of these values is 5. So we buy lodging for only 5 nights, at a cost of 5 * 75 = 375 euros. We should have 25 euros left. This also implies that we slept in the train station for 7 - 5 = 2 nights. t.visit(paris, 7); System.out.println(t.getCurrentMoney ()); // expected 25 System.out.println(t.getNightsInStation () ); // expected 2 Paris is a lot of fun, so we stay another week. This time we discover we have only enough money for zero nights lodging. The smaller of zero and 7 is zero, so we purchase zero nights lodging at a cost of zero times 75. So we still have 25 euros, but we've slept another 7-0 = 7 nights in the train station. t.visit(paris, 7); System.out.println(t.getCurrentMoney ()); // expected 25 System.out.println(t.getNightsInStation()); // expected 9 Ok, we're tired, but are we SOL? The cost of a postcard from Paris is 4 euros. Is that more than we have left? The expression 4 > 25 is false, so we are not yet SOL. Let's send a postcard home! It will cost us just 4 euros. t.sendPostcardsHome (1); System.out.println(t.getCurrentMoney ()); // expected 21 Before we call home and ask for more money, let's really get on Mom and Dad's good side. Try sending 12 postcards! With 21 euros, the maximum number of postcards we can send is 5. The smaller of 5 and 12 is 5, so that's the number we actually send. We should see our funds go down by 5 times the postcard cost, or 20 euros, leaving us one euro. t.sendPostcardsHome (12); System.out.println(t.getCurrent Funds()); // expected 1 At this point we're technically SOL: we have 1 euro, the cost of sending a postcard is 4 euros, and the expression 4> 1 is true. System.out.println(t.isSOL () ); // expected true But, we've sent a total of 6 postcards home. When we call and ask for money, our funds should go up by 6 times SYMPATHY_FACTOR, 6 * 30 = 180, leaving us sitting pretty with 181 euros. t.callHome ForMoney(); System.out.println(t.getCurrentMoney ()); // expected 181 If we ask for money again now, nothing should happen - Mom and Dad will have no more sympathy for us until we send more postcards. t.callHome ForMoney(); System.out.println(t.getCurrentMoney ()); // still just 181 PROBLEM: Message: For new Backpacker (25, Paris/75), after 1 postcard, then call HomeForMoney, getCurrentMoney should return 51. expected: but was: PROBLEM: Message: For new Backpacker (25, Paris/75), after 6 postcards, then call HomeForMoney, getCurrentMoney should return 181. expected: but was: PROBLEM: Message: For new Backpacker (25, Paris/75), after 1 postcard, then callHomeForMoney twice, getCurrentMoney should return 51. expected: but was: PROBLEM: Message: For new Backpacker (25, Barcelona/45), after send 3 postcards from Barcelona 45, 1 from Paris/75, 2 from Barcelona 45, 5 from Paris/75, then callHomeForMoney. getCurrentMoney should return 243. expected: but was: public void callHomeForMoney () { //Money from home is n time ( no of cards) * sypmathy factor. int home_money = total_cards * SYMPATHY_FACTOR; current fund = current fund + home_money public void sendPostcardsHome(int howMany) { if (current city == "Paris") { int cost = paris_postcard_cost * howMany; int max_cards = current_fund / paris_postcard_cost; if (max_cards but was: PROBLEM: Message: For new Backpacker (25, Barcelona/45), after send 3 postcards from Barcelona 45, 1 from Paris/75, 2 from Barcelona/45, 5 from Paris/75, getCurrentMoney should return 3. expected: but was: PROBLEM: Message: For new Backpacker 25, Paris/75), after 1 postcard, then callHomeForMoney, getCurrentMoney should return 51. expected: but was: PROBLEM: Message: For new Backpacker (25, Paris/75), after 6 postcards, then callHomeForMoney, getCurrentMoney should return 181. expected: but was: PROBLEM: Message: For new Backpacker (25, Paris/75), after 1 postcard, then callHomeForMoney twice, getCurrentMoney should return 51. expected: but was: PROBLEM: Message: For new Backpacker (25, Barcelona/45), after send 3 postcards from Barcelona 45, 1 from Paris/75, 2 from Barcelona/45, 5 from Paris/75, then callHomeForMoney, getCurrentMoney should return 243. expected: but was: public int getCurrentMoney () { if (current_city == "London") { current_city_cost = current_fund - (200 * 3); if (current_city == "Paris"){ current_city_cost = current_fund -(75 * 7); } if (current_city == "Prague") { current_city_cost = current_fund -(7 *12); if (current_city == "Barcelona") { current_city_cost = current_fund 7 45; return current_fund; public String getCurrentCity () Returns the name of the Backpacker's current city. public int getCurrentMoney () Returns the amount of money the Backpacker currently has. Next, what happens to the funds if we follow the same itinerary as above? For Rome, we can determine (from the City object) that we have enough money for 10 nights. We're staying 2 nights, which is less than 10, so we buy lodging for 2 nights. That costs 2 * 50, or 100 euros, so we expect to have 400 left. t = new Backpacker (500, paris); 1/ start over // initial state System.out.println(t.getCurrentMoney ()); // expected 500 // visit a city t.visit(rome, 2); System.out.println(t.getCurrentMoney ()); // expected 400 When we go back to Paris for a week, it's a bit different. We determine (from the City object) that 400 euros is enough for only 5 nights. The desired number is 7 nights, and the smaller of these values is 5. So we buy lodging for only 5 nights, at a cost of 5 * 75 = 375 euros. We should have 25 euros left. This also implies that we slept in the train station for 7 - 5 = 2 nights. t.visit(paris, 7); System.out.println(t.getCurrentMoney ()); // expected 25 System.out.println(t.getNightsInStation () ); // expected 2 Paris is a lot of fun, so we stay another week. This time we discover we have only enough money for zero nights lodging. The smaller of zero and 7 is zero, so we purchase zero nights lodging at a cost of zero times 75. So we still have 25 euros, but we've slept another 7-0 = 7 nights in the train station. t.visit(paris, 7); System.out.println(t.getCurrentMoney ()); // expected 25 System.out.println(t.getNightsInStation()); // expected 9 Ok, we're tired, but are we SOL? The cost of a postcard from Paris is 4 euros. Is that more than we have left? The expression 4 > 25 is false, so we are not yet SOL. Let's send a postcard home! It will cost us just 4 euros. t.sendPostcardsHome (1); System.out.println(t.getCurrentMoney ()); // expected 21 Before we call home and ask for more money, let's really get on Mom and Dad's good side. Try sending 12 postcards! With 21 euros, the maximum number of postcards we can send is 5. The smaller of 5 and 12 is 5, so that's the number we actually send. We should see our funds go down by 5 times the postcard cost, or 20 euros, leaving us one euro. t.sendPostcardsHome (12); System.out.println(t.getCurrent Funds()); // expected 1 At this point we're technically SOL: we have 1 euro, the cost of sending a postcard is 4 euros, and the expression 4> 1 is true. System.out.println(t.isSOL () ); // expected true But, we've sent a total of 6 postcards home. When we call and ask for money, our funds should go up by 6 times SYMPATHY_FACTOR, 6 * 30 = 180, leaving us sitting pretty with 181 euros. t.callHome ForMoney(); System.out.println(t.getCurrentMoney ()); // expected 181 If we ask for money again now, nothing should happen - Mom and Dad will have no more sympathy for us until we send more postcards. t.callHome ForMoney(); System.out.println(t.getCurrentMoney ()); // still just 181

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions