While loop not repeating in java - java

A program that takes ticket orders and provides the total. It's not letting me answer the question whether, i would like to buy more tickets. I'm a beginner, If you guys could guide me or suggest any upgrades that would be helpful.
package ridecalc;
import java.util.Scanner;
/** *
1. #author */
public class Ridecalc {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
double tickets = 0;
double totprice;
String moretickets = "";
System.out.println("Hi! welcome to JP's amusment park");
do {
if (response()) {
System.out.println("How many tickets would you like to purchase ?");
tickets = in.nextInt();
} else {
totprice = 0;
}
totprice = calc(tickets);
System.out.println("The total amount for the tickets are :" + totprice);
System.out.println("Would you like to buy more tickets ?(y/n)");
moretickets = in.nextLine();
} while (moretickets.equalsIgnoreCase("y"));
}
public static boolean response() {
Scanner in = new Scanner(System.in);
String response = "";
System.out.println("Would you like to buy any tickets (y/n)");
response = in.nextLine();
if (response.equalsIgnoreCase("y")) {
return true;
} else {
return false;
}
}
public static double calc(double tickets) {
double totprice;
totprice = (tickets * 20);
return totprice;
}
}
List item

Firstly, your response.equalsIgnoreCase("y") never evaluates to true because it is always an empty string, there has been no affectation to the variable response. So I added a boolean rps that will store the response of the user from your function response() and loop until it is true.
EDIT: Fixed usage of Scanner, only one Scanner instance
EDIT 2: Fixed double condition
package ridecalc;
import java.util.Scanner;
/** *
1. #author */
public class some {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
double tickets = 0;
double totprice;
String moretickets = "";
System.out.println("Hi! welcome to JP's amusment park");
boolean rps = true;
while( rps ){
if ( (rps = response(in)) == true) {
System.out.println("How many tickets would you like to purchase ?");
tickets = in .nextInt();
} else {
totprice = 0;
}
totprice = calc(tickets);
System.out.println("The total amount for the tickets are :" + totprice);
System.out.println("Would you like to buy more tickets ?(y/n)"); // this doesn't seem necessary since there is no test following
in.next();
moretickets = in.nextLine();
}
}
public static boolean response(Scanner in) {
String response = "";
System.out.println("Would you like to buy any tickets (y/n)");
response = in.nextLine();
if (response.equalsIgnoreCase("y")) {
System.err.println("here");
return true;
} else {
return false;
}
}
public static double calc(double tickets) {
double totprice;
totprice = (tickets * 20);
return totprice;
}
}

Related

How does one pass parameters between methods and correctly call the method using Java?

The program should do the following:
Write a method called getheartRate that takes no parameters and returns an int (heartRate).
This method prompts the user for the patient's heart rate, reads
their input from the command line, and returns this value.
Write a method called checkHeartRate that takes an int parameter (the heart rate) and returns
a String (result). If the heart rate is above 100, return the value "High". If the heart rate is below
60, return the value "Low". Otherwise return "Normal".
Write a method called printHRResult that takes a String parameter, which is the result
from the method checkHeartRate. Print this value to the command line.
Call all three methods from the main method using appropriate parameter passing.
So far I have:
public class UnitSixInClassFall2018 {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
UnitSixInClassFall2018 u = new UnitSixInClassFall2018();
u.getHeartRate();
System.out.println();
Scanner scan = new Scanner(System.in);
u.checkHeartRate(0);
// END MAIN
}
public int getHeartRate(){
System.out.print("Please enter your heart rate: ");
Scanner scan = new Scanner(System.in);
int heartRate = scan.nextInt();
return 0;
}
public void checkHeartRate(int heartRate){
if (heartRate > 100) {
String result = "High";
}
else if (heartRate < 60) {
String result = "Low";
}
else {
String result = "Normal";
}
}
public String printHRResults(String result) {
System.out.print("Your hear rate is " + result + ".");
return result;
}
}
When this is run, all that is output is "Please enter your heart rate: ". Once I enter an integer, the program ends. What is being done incorrectly?
You should change this method to return the heart rate like this:
public int getHeartRate(){
System.out.print("Please enter your heart rate: ");
Scanner scan = new Scanner(System.in);
int heartRate = scan.nextInt();
// Also add this
scan.close();
return heartRate;
}
And change this method to return the result:
public String checkHeartRate(int heartRate){
if (heartRate > 100) {
return "High";
}
else if (heartRate < 60) {
return "Low";
}
else {
return "Normal";
}
}
Then in your main method:
// get the heart rate
int heartRate = u.getHeartRate();
// Call the checkHeartRate method
String result = checkHeartRate(heartRate);
// call the printHRResults
printHRResults(result);
That should solve your problem.
First of all, you are creating two Scanner objects with the same input type (System.in), which isn't recommended. Instead, just make one Scanner object and use it everywhere in your program. This post has some good info.
An improved version of your code with an improved use of the Scanner object is as follows:
public UnitSixInClassFall2018 {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
NewMain u = new NewMain();
int heartRate = u.getHeartRate();
System.out.println();
String result = u.checkHeartRate(heartRate);
u.printHRResults(result);
scan.close(); // Close the scanner once you are completely done using it
}
public int getHeartRate() {
System.out.print("Please enter your heart rate: ");
return scan.nextInt(); // Return the input of the user
}
public String checkHeartRate(int heartRate) {
String result = ""; // Initialize some default value
if (heartRate > 100) {
result = "High";
}
else if (heartRate < 60) {
result = "Low";
}
else {
result = "Normal";
}
return result; // Return the result calculated from the if-statements
}
public void printHRResults(String result) {
System.out.print("Your heart rate is " + result + ".");
// Originally this method returned a string but that seems unnecessary
}
}

I'm having problems understanding how to get a variable out of this ArrayList

I am making a Recipe Box for school and I need help understanding how to access a single variable inside an ArrayList. I only need to access the totalCalories variable in the recipe file, not the ingredient so that I can add the total number of calories in the recipe itself. Here is the code.
package recipebox;
import java.util.Scanner;
import java.util.ArrayList;
public class Recipe {
private String recipeName;
private int servings;
private ArrayList recipeIngredients;
private double totalRecipeCalories;
public String getRecipeName() {
return recipeName;
}
public void setRecipeName(String recipeName) {
this.recipeName = recipeName;
}
public double getTotalRecipeCalories() {
return totalRecipeCalories;
}
public void setTotalRecipeCalories(double totalRecipeCalories) {
this.totalRecipeCalories = totalRecipeCalories;
}
public ArrayList getRecipeIngredients() {
return recipeIngredients;
}
public void setRecipeIngredients(ArrayList recipeIngredients) {
this.recipeIngredients = recipeIngredients;
}
public int getServings() {
return servings;
}
public void setServings(int servings) {
this.servings = servings;
}
public Recipe() {
this.recipeName = "";
this.servings = 0;
this.recipeIngredients = new ArrayList<>();
this.totalRecipeCalories = 0;
}
public Recipe(String recipeName, int servings, ArrayList <String> recipeIngredients, double totalRecipeCalories) {
this.recipeName = recipeName;
this.servings = servings;
this.recipeIngredients = recipeIngredients;
this.totalRecipeCalories = totalRecipeCalories;
}
public void printRecipe() {
int singleServingCalories = (int)(totalRecipeCalories/getServings());
System.out.println("Recipe: " + getRecipeName());
System.out.println("Serves: " + getServings());
System.out.println("Ingredients:");
System.out.println(recipeIngredients);
System.out.println("Each serving has " + singleServingCalories + " Calories.");
}
public void addIngredient() {
recipeIngredients.add(Ingredient.createNewIngredient());
}
public static void main(String[] args) {
createNewRecipe();
}
public static Recipe createNewRecipe() {
double totalRecipeCalories = 0;
ArrayList <String> recipeIngredients = new ArrayList();
boolean addMoreIngredients = true;
Recipe myRecipe = new Recipe();
Scanner scnr = new Scanner(System.in);
System.out.println("Please enter the recipe name: ");
while (!scnr.hasNextLine()){
System.out.println("Invalid input");
System.out.println("Please enter the recipe name: ");
scnr.nextLine();
}
String recipeName = scnr.nextLine();
System.out.println("Please enter the number of servings: ");
while (!scnr.hasNextInt()){
System.out.println("Invalid input");
System.out.println("Please enter the number of servings: ");
scnr.nextLine();
}
int servings = scnr.nextInt();
do {
myRecipe.addIngredient();
totalRecipeCalories += recipeIngredients.get(totalCalories);
I didn't include the rest of it since it won't matter. That last line is wrong and is the one that needs fixing. Now here is the ingredient code.
package recipebox;
import java.util.Scanner;
public class Ingredient {
private String nameOfIngredient;
private float numberUnits;
private String unitMeasurement;
private int numberCaloriesPerUnit;
private double totalCalories;
/**
* #return the nameOfIngredient
*/
public String getNameOfIngredient() {
return nameOfIngredient;
}
/**
* #param nameOfIngredient the nameOfIngredient to set
*/
public void setNameOfIngredient(String nameOfIngredient) {
this.nameOfIngredient = nameOfIngredient;
}
/**
* #return the numberUnits
*/
public float getNumberUnits() {
return numberUnits;
}
/**
* #param numberUnits the numberUnits to set
*/
public void setNumberUnits(float numberUnits) {
this.numberUnits = numberUnits;
}
/**
* #return the numberCaloriesPerUnit
*/
public int getNumberCaloriesPerUnit() {
return numberCaloriesPerUnit;
}
/**
* #param numberCaloriesPerUnit the numberCaloriesPerUnit to set
*/
public void setNumberCaloriesPerUnit(int numberCaloriesPerUnit) {
this.numberCaloriesPerUnit = numberCaloriesPerUnit;
}
/**
* #return the totalCalories
*/
public double getTotalCalories() {
return totalCalories;
}
/**
* #param totalCalories the totalCalories to set
*/
public void setTotalCalories(double totalCalories) {
this.totalCalories = totalCalories;
}
/**
* #return the unitMeasurement
*/
public String getUnitMeasurement() {
return unitMeasurement;
}
/**
* #param unitMeasurement the unitMeasurement to set
*/
public void setUnitMeasurement(String unitMeasurement) {
this.unitMeasurement = unitMeasurement;
}
public Ingredient() {
this.nameOfIngredient = "";
this.numberUnits = 0.00f;
this.unitMeasurement = "";
this.numberCaloriesPerUnit = 0;
this.totalCalories = 0.0;
}
public Ingredient(String nameOfIngredient, float numberUnits, String unitMeasurement, int numberCaloriesPerUnit, double totalCalories) {
this.nameOfIngredient = nameOfIngredient;
this.numberUnits = numberUnits;
this.unitMeasurement = unitMeasurement;
this.numberCaloriesPerUnit = numberCaloriesPerUnit;
this.totalCalories = totalCalories;
}
public static Ingredient createNewIngredient() {
Scanner scnr = new Scanner(System.in);
System.out.println("Please enter the name of the ingredient: ");
while (!scnr.hasNextLine()){
System.out.println("Invalid input");
System.out.println("Please enter the name of the ingredient: ");
scnr.nextLine();
}
String nameOfIngredient = scnr.nextLine();
System.out.println("What unit of measurement will you be using? ");
while (!scnr.hasNextLine()){
System.out.println("Invalid input");
System.out.println("What unit of measurement will you be using? ");
scnr.nextLine();
}
String unitMeasurement = scnr.nextLine();
System.out.println("Please enter the number of " + unitMeasurement + " of " + nameOfIngredient + " we will need: ");
while (!scnr.hasNextFloat()) {
System.out.println("Invalid input");
System.out.println("Please enter the number of " + unitMeasurement + " of " + nameOfIngredient + " we will need: ");
scnr.nextLine();
}
float numberUnits = scnr.nextFloat();
System.out.println("Please enter the number of calories per " + unitMeasurement + ": ");
while (!scnr.hasNextInt()) {
System.out.println("Invalid input");
System.out.println("Please enter the number of calories per " + unitMeasurement + ": ");
scnr.nextLine();
}
int numberCaloriesPerUnit = scnr.nextInt();
double totalCalories = numberUnits * numberCaloriesPerUnit;
System.out.println(nameOfIngredient + " uses " + numberUnits + " " + unitMeasurement + " and has " + totalCalories + " calories.");
recipebox.Ingredient tempIngredient = new recipebox.Ingredient(nameOfIngredient, numberUnits, unitMeasurement, numberCaloriesPerUnit, totalCalories);
return tempIngredient;
}
}
Now when I debug the recipe file, right after it returns from getting the ingredients, I can see in the variables list the variable I need, but I can't figure out how to get to it.
This is what the debug variable menu looks like
If someone can help me access that one variable and maybe explain in beginner terms how you did it, I'd be very grateful. Thanks.
The variable recipeIngredients is a List and not an object. The list contains object of type Ingredient. So to the value of the total calories from an ingredient in the list you need to access a particular ingredient in that list first and then take its property.
So it would be recipeIngredients.get(0).getTotalCalories() - to get the total calories for the first ingredient in the list
If you want it for the whole recepy you would need a loop that goes through that list and calculates. Something like:
int calories;
for(Object ingredient: recipeIngredients)
calories+= ((Ingredient)ingredient).getTotalCalories();
Also in the code:
System.out.println(recipeIngredients);
You will not print anything useful for the same reason. You need to go through each ingredient and print it in a pretty way.
You might also consider making that list of type Ingredient using generics so you don't need to cast and you are using it just for ingredients anyway

Displaying a function calculation

I'm encountering an issue on a program I'm compiling. i got to display the actual calculation on function 2.The main program is called display11 and I'm calling the functions on the other class. can't figure it out whats wrong that is not displaying the loop. thanks a lot
import java.util.Scanner;
/**
*
* #author ec1302696
*/
public class Functions
{
private int n;
public void string_function(String name)
{
int optionChosen;
String fname;
String sname;
Scanner keyboard = new Scanner(System.in);
Scanner sc = new Scanner(System.in);
Functions fun = new Functions();
System.out.println("Please enter full name");
fname = sc.nextLine(); //accept first name entered by user
//****enter as a comment for now fun.first(fname);
fun.createname(fname);// this create name
//display this is option 1,administrator name admin
//ask for full name for generating username
//call createname passing the username
}
public void number_function(String admin)
{
{
int n, c, fact = 1;
System.out.println("Enter a number to calculate it's factorial");
Scanner in = new Scanner(System.in);
n = in.nextInt();
if ( n < 0 )
System.out.println("Number should be non-negative.");
else
{
for ( c = 1 ; c <= n ; c++ )
fact = fact*c;
System.out.println("Factorial of "+n+" is = "+fact);
}
// return fact;
//this is option 2 ,administrator name admin
//read the factorial
//calcualte the fatorial
// print it
}
}
public void createname(String username)
{
String fname = fname.substring(0,1);
System.out.println("The usernameis " + fname);
//string calcualte the string function to find the first letter ,and second name.
//concatenate and print it.
}
}
import java.util.Scanner;
/**
*
* #author ec1302696
*/
public class Display11 {
/**
* #param args the command line arguments
*/
public static void main(String[] args)
{
Functions fun = new Functions();// this create teh functions
int optionChosen;
String admin;
Scanner keyboard = new Scanner(System.in);
Scanner sc = new Scanner(System.in);
System.out.println("Please enter your name");
admin = keyboard.nextLine();
{
System.out.println("Welcome please select option from menu below");
}
System.out.println("OPTION 1 – USERNAME");
System.out.println("OPTION 2 - CALCULATE THE FACTORIAL");
System.out.println("OPTION 3 - EXIT");
optionChosen = keyboard.nextInt();
if (optionChosen == 1)
{
fun.string_function(admin);
}
else if (optionChosen == 2) {
{
fun.number_function(admin);
}
}
else if (optionChosen == 3)
{
}
}
}
If you need to show the calculation of the factorial, change the calculation loop to something like this:
StringBuilder result = new StringBuilder("Factorial of ").append(n).append(" is ");
for ( c = n ; c >0 ; c-- )
{
result.append(c);
if(c>1)
{
result.append(" * ");
}
fact = fact*c;
}
result.append(" = ").append(fact);
System.out.println(result);

Need to add the numbers from an object

I am writing a program that takes names, dates and numbers from a user as many times as they enter it and then adds up the numbers that were entered. If you look at the third for loop you will see where I am trying to add. I tried doing total = cust[i].amount + total; but I cannot access amount for some reason.
This is for an assignment.(I know were not supposed to post homework questions on here but I'm stumped.)The only data member Customer is to have is name
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
final int MAX = 9999;
Customer [] cust = new Customer[MAX];
int choice = 0;
int cnt;
double total = 0;
for(cnt=0; cnt < MAX && (choice == 1 || choice ==2 || choice == 0); cnt++){
System.out.println("For a Service customer type 1, for a Purchaser type 2, to terminate the program press 9");
choice = s.nextInt();
switch (choice){
case 1:
cust [cnt] = new Service();
break;
case 2:
cust [cnt] = new Purchaser();
break;
default:
break;
}
}
for(int i=0; i < cnt; i++){
if(cust[i]!= null)
cust[i].showData();
}
for(int i=0; i < cnt; i++ ){
total = cust[i].amount + total;
}
s.close();
}
}
interface Functions {
public void getData();
public void showData();
}
abstract class Customer implements Functions {
protected String name;
}
class Purchaser extends Customer {
protected double payment;
public Purchaser(){
getData();
}
public void getData() {
Scanner s = new Scanner(System.in);
System.out.println("Enter the name of the customer");
name = s.nextLine();
System.out.println("Enter payment amount: ");
payment = s.nextDouble();
}
public void showData() {
System.out.printf("Customer name: %s Payment amount is: %.2f\n",name,payment);
}
}
class Service extends Customer {
protected String date;
protected double amount;
public Service () {
getData();
}
public void getData() {
Scanner s = new Scanner(System.in);
System.out.println("Enter the name of the customer");
name = s.nextLine();
System.out.println("Enter date of Service: ");
date = s.nextLine();
System.out.println("Enter the cost of Service: ");
amount = s.nextDouble();
}
public void showData() {
System.out.printf("Customer name: %s The date is: %s, the Amount owed is: %.2f\n",name, date, amount);
}
There's no field amount in the class Customer.
There are several issues, but you should
// Use one loop...
for(int i=0; i < cnt; i++){
if(cust[i]!= null) { // <-- check for null.
cust[i].showData();
/* or
if (cust instanceof Service) {
total += ((Service)cust[i]).amount; // <-- assuming a public amount
// field in Service. This is not a good
// practice, but your question is difficult to
// answer.
}
*/
total += cust[i].getAmount(); // <-- a method.
}
}
That is add a getAmount to your interface if you want to get the amount (or, to make this code work - change the access modifier and add a public field named amount to Customer and remove the shadowing fields in your subclasses).
Or, you can learn about Collections (which I strongly recommend you do anyway) - and actually use the correct storage method - perhaps ArrayList.
This is one solution that I could come up with, where we add a getAmount method to the interface:
import java.util.Scanner;
public class home {
/**
* #param args
*/
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
final int MAX = 2;
Customer [] cust = new Customer[MAX];
int choice = 0;
int cnt;
double total = 0;
for(cnt=0; cnt < MAX && (choice == 1 || choice ==2 || choice == 0); cnt++){
System.out.println("For a Service customer type 1, for a Purchaser type 2, to terminate the program press 9");
choice = s.nextInt();
switch (choice){
case 1:
cust [cnt] = new Service();
break;
case 2:
cust [cnt] = new Purchaser();
break;
default:
break;
}
}
for(int i=0; i < cnt; i++){
if(cust[i]!= null)
cust[i].showData();
total = cust[i].getAmount() + total;
}
s.close();
}
}
abstract class Customer implements Functions {
protected String name;
}
import java.util.Scanner;
class Service extends Customer {
protected String date;
protected double amount;
public Service () {
getData();
}
public void getData() {
Scanner s = new Scanner(System.in);
System.out.println("Enter the name of the customer");
name = s.nextLine();
System.out.println("Enter date of Service: ");
date = s.nextLine();
System.out.println("Enter the cost of Service: ");
amount = s.nextDouble();
}
public double getAmount(){
return this.amount;
}
public void showData() {
System.out.printf("Customer name: %s The date is: %s, the Amount owed is: %.2f\n",name, date, amount);
}
}
import java.util.Scanner;
class Purchaser extends Customer {
protected double payment;
public Purchaser(){
getData();
}
public double getAmount(){
return this.payment;
}
public void getData() {
Scanner s = new Scanner(System.in);
System.out.println("Enter the name of the customer");
name = s.nextLine();
System.out.println("Enter payment amount: ");
payment = s.nextDouble();
}
public void showData() {
System.out.printf("Customer name: %s Payment amount is: %.2f\n",name,payment);
}
}
interface Functions {
public void getData();
public void showData();
public double getAmount();
}

How to get data from LinkedList?

Here is an example output that I am looking for, for my program.
Example Output
On each line enter a stadium name and the game revenue
Enter done when you are finished
Giants 1000
Foxboro 500
Giants 1500
done
Enter the name of a stadium to get the total revenue for:
Giants
The total revenue is 2500.00
I got everything working but the total revenue at the end. I'm not sure how to go into my linkedlist and grab the game revenue and display it.. This is my code right now, and what I have been messing with...
import java.util.LinkedList;
import java.util.Scanner;
public class LinkedLists {
private final Scanner keyboard;
private final LinkedList<String> stadiumNames;
private final LinkedList<Integer> gameRevenue;
public LinkedLists() {
this.keyboard = new Scanner(System.in);
this.stadiumNames = new LinkedList<String>();
this.gameRevenue = new LinkedList<Integer>();
}
public void addData(String stadium, int revenue){
stadiumNames.add(stadium);
gameRevenue.add(revenue);
}
public void loadDataFromUser() {
System.out.println("On each line enter the stadium name and game revenue.");
System.out.println("Enter done when you are finished.");
boolean done = false;
while(!done) {
System.out.print("Enter the name of the stadium:");
String stadium = keyboard.next();
if (stadium.equals("done")) {
done = true;
} else {
System.out.print("Enter game revenue: ");
addData(stadium, keyboard.nextInt());
}
}
}
// return -1 if not found
public int getIndexForName(String name) {
if(stadiumNames.contains(name)){
System.out.println("The total revenue is: " +gameRevenue.get(0));
System.exit(0);
}
return -1;
}
public void showInfoForName(String name) {
int index = getIndexForName(name);
if (index==-1) {
System.out.println("There is no stadium named " + name);
} else {
}
}
public void showInfoForName() {
System.out.println("Enter the name of the stadium to get the total revenue for it.");
showInfoForName(keyboard.next());
}
public static void main(String[] args) {
LinkedLists pgm = new LinkedLists();
pgm.loadDataFromUser();
pgm.showInfoForName();
}
}
Try this:
public int getIndexForName(String name) {
if (stadiumNames.contains(name)) {
int total = 0;
for (int i = 0 ; i < stadiumNames.size() ; i++)
if (stadiumNames.get(i).equals(name))
total += gameRevenue.get(i);
System.out.println("The total revenue is: " + total);
System.exit(0);
}
return -1;
}
There are better ways of doing this though. I would perhaps use a Map that maps each stadium name to its total revenue. You could update this map in the addData method.
using hash map is much cleaner, plus you can save the total on the side and not calculate it:
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;
/**
* User: user
* Date: 09/09/2012
*/
public class Blah {
private Scanner keyboard;
private Map<String, Integer> stadiumRevenues;
private Integer total = 0;
public Blah() {
this.keyboard = new Scanner(System.in);
this.stadiumRevenues = new HashMap<String, Integer>();
}
public void addData(String stadium, int revenue){
stadiumRevenues.put(stadium, revenue);
total += revenue;
}
public void loadDataFromUser() {
System.out.println("On each line enter the stadium name and game revenue.");
System.out.println("Enter done when you are finished.");
boolean done = false;
while(!done) {
System.out.print("Enter the name of the stadium:");
String stadium = keyboard.next();
if (stadium.equals("done")) {
done = true;
} else {
System.out.print("Enter game revenue: ");
addData(stadium, keyboard.nextInt());
}
}
}
public int getTotal() {
return total;
}
// return -1 if not found
public int getIndexForName(String name) {
Integer rev = stadiumRevenues.get(name);
if(rev != null){
System.out.println("The total revenue is: " +rev);
System.exit(0);
}
return -1;
}
public void showInfoForName(String name) {
Integer rev = stadiumRevenues.get(name);
if (rev == null) {
System.out.println("There is no stadium named " + name);
} else {
}
}
public void showInfoForName() {
System.out.println("Enter the name of the stadium to get the total revenue for it.");
showInfoForName(keyboard.next());
}
public static void main(String[] args) {
Blah pgm = new Blah();
pgm.loadDataFromUser();
pgm.showInfoForName();
}
}

Categories

Resources