0

Ok, so I run this code and it give me the error:

SammysRentalPriceWithMethods.java:49: error: variable Minutes might not have been initialized
 int TOTAL_COST = Minutes - 60 * 1 + 40;
 ^

I have no idea how to fix it, also I am sorry if my code is inefficient, I have only been on Java for 3 weeks, very much a beginnner.

import java.util.Scanner; 
public class SammysRentalPriceWithMethods {
 public static void main(String[] args) {
 rentalTime();
 companyMotto();
 whenIGetMoney();
 }
 public static int rentalTime() { 
 int Minutes;
 Scanner inputDevice = new Scanner(System.in);
 System.out.print("Enter total minutes equipment was rented:");
 Minutes = inputDevice.nextInt();
 return Minutes;
 }
 public static void companyMotto() {
 System.out.println(
 "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS \r\n" + 
 "S S \r\n" + 
 "S S \r\n" +
 "S S \r\n" +
 "S S \r\n" +
 "S S \r\n" +
 "S Sammy's makes it fun in the sun S \r\n" +
 "S S \r\n" + 
 "S S \r\n" +
 "S S \r\n" +
 "S S \r\n" +
 "S S \r\n" +
 "S S \r\n" +
 "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS \r\n");
 }
 public static void whenIGetMoney() {
 final int HOURLY_RATE = 40;
 final int EXTRA_MIN_RATE = 1; 
 int Minutes; 
 int TOTAL_COST = Minutes - 60 * 1 + 40;
 System.out.println("You rented our equipment for " + Minutes + " minutes!");
 System.out.println("The total cost of an " + Minutes + " minute rental is $" + TOTAL_COST + ".");
 }
}

I get the error in my last method telling me that the varible Minutes isnt initialized, got any ideas?

Jean-Rémy Revy
5,7153 gold badges44 silver badges65 bronze badges
asked Sep 22, 2014 at 19:32

2 Answers 2

1

I think you should try this:

int min = rentalTime();
companyMotto();
whenIGetMoney(min);

with this modification:

public static void whenIGetMoney(int min) {
 final int HOURLY_RATE = 40;
 final int EXTRA_MIN_RATE = 1; 
 int Minutes = min;
 ...
answered Sep 22, 2014 at 19:38
Sign up to request clarification or add additional context in comments.

1 Comment

I would like to let you know that, I. Love. You. This worked perfectly! dsfajfldahskflaifudsakdflh Sweet baby Jesus Thank you!
1

You can't use a local variable without initializing it first. Your Minutes variable isn't initialized and you try to use it. just declare it like int Minutes = 0; in the whenIGetMoney() method. Anyway, the result won't be what you expect to be, as the variable Minutes has not the correct value in it.

answered Sep 22, 2014 at 19:33

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.