Question
Tried to convert from the same c++ program, but I cant figure out what is wrong. I feel like something is wrong at the //priming
Tried to convert from the same c++ program, but I cant figure out what is wrong. I feel like something is wrong at the
//priming read, or anywhere below that.
Using Multidimensional Arrays
Summary
In this lab, you will complete a Java program that uses a two-dimensional array to store data for the Building Block Day Care Center. The day care center charges varying weekly rates depending on the age of the child and the number of days per week the child attends. The program should allow users to enter the age of the child and the number of days per week the child will be at the day care center. The program should output the appropriate weekly rate. The file provided for this lab contains all of the necessary variable declarations, except the two-dimensional array. You need to write the input statements and the code that initializes the two-dimensional array, determines the weekly rate, and prints the weekly rate. Comments in the code tell you where to write your statements. Weekly rates can be found in the provided table.
Instructions
Age: | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|
0 | 30.00 | 60.00 | 88.00 | 115.00 | 140.00 |
1 | 26.00 | 52.00 | 70.00 | 96.00 | 120.00 |
2 | 24.00 | 46.00 | 67.00 | 89.00 | 110.00 |
3 | 22.00 | 40.00 | 60.00 | 75.00 | 88.00 |
4 + | 20.00 | 35.00 | 50.00 | 66.00 | 84.00 |
import java.util.Scanner;
public class DayCare { public static void main(String args[]) { // Declare two-dimensional array here. double rate[][] = { { 30.00, 60.00, 88.00, 115.00, 140.00 }, { 26.00, 52.00, 70.00, 96.00, 120.00 }, { 24.00, 46.00, 67.00, 89.00, 110.00 }, { 22.00, 40.00, 60.00, 75.00, 88.00 }, { 20.00, 35.00, 50.00, 66.00, 84.00 } };
// Declare other variables. int numDays; int age; String numDaysString; String ageString; int QUIT = 99; Scanner input = new Scanner(System.in); // This is the work done in the getReady() method // Perform a priming read to get the age of the child. ageString = JOptionpane.showInputDialog( "Enter age of child or 99 to quit: "); age = Integer.parseInt(ageString); while(age != QUIT) { // This is the work done in the determineRateCharge() method // Ask the user to enter the number of days if(age > 4) age = 4; numDaysString = JOptionPane.showInputDiaglog( "Enter number of days: "); numDays = Integer.parseInt(numDaysString); // Print the weekly rate system.out.println("Rate is $" + rate[age][numDays-1]); ageString =
// Ask the user to enter the next child's age JOptionPane.showInputDiaglog( "Enter age of child or 99 to quit: "); age = Integer.parseInt(ageString); } // This is the work done in the finish() method System.out.println("End of program");
System.exit(0); } // End of main() method. } // End of DayCare class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started