Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 import java.io.*; 2 import java.util.*; 3 4 // Read only region start 5 class UserMainCode 6 { 7 8 9 How to Attempt?

 image

1 import java.io.*; 2 import java.util.*; 3 4 // Read only region start 5 class UserMainCode 6 { 7 8 9 How to Attempt? Piggy bank Rishe has two piggy banks. In a short period of time, he wants to save money for the trip with his friends. He has decided to save money for N number of days, ie Day-1 to Day- N (inclusive), which is given as input1. He starts on Day-1 by adding the given starting amount input2 to one of the piggy bank, let's say piggy bank-1. On odd days, he will double the money he had saved the previous day in piggy bank-1 and on even days, he will calculate half of what he had saved so far in the piggy bank-1 and save it in piggy bank-2. Calculate the total amount saved on odd days and even days separately. Return the output as "total amount saved on odd days:total amount saved on even days" Function prototype: String piggyBank(int input1, int input2) Note: input1 and input2 is always greater than 0 Example-1 input1: 9 input2: 2 output 62:26 Explanation: 10 11 12 13 public String piggyBank(int input1, int input2){ // Read only region end // Write code here... throw new UnsupportedOperationException("piggyBank(int input1 } } Il tests.mettl.com is sharing your screen. Stop sharing Hide Compile and Test output: 62:26 Explanation: Day 1 Day 2 Day 3 Day4 Day5 Day6 Day7 Day& Day9 Total Piggy bank 1 2 nigh (Odd days) Piggy bank 2 1 3 (Even days) Day-1=2 (input2) Day-2=> (2/2) = 1 Day-3=> 2+2=4 Day-4=> (6/2) = 3 Day-5 => 4+4=8 Day-6=> (14/2) = 7 Day-7=>8+8 = 16 Day-8=> (30/2) = 15 Day-9=> 16 + 16 = 32 Mettl Online Assessment 2021-2031 12 a 2 # Q W S 8 16 32 Z 7 15 29 62 2 import java.util.*; 3 // Read only region start 1456789 class UserMainCode { public String piggyBank(int input1, int input2){ // Read only region end // Write code here... throw new UnsupportedOperationException("piggyBank (int input1 10 11 12 26 } 26 13 } I tests.mettl.com is sharing your screen. Stop sharing Hide Custon Compile and Test Need Help? Contact us: +1 (800) 265-6038 +91 80471-90902 A J $ % 3 4 E R T hp 6 & 7 Y H 8 156325169 insert JK X C B N M Powered By

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions