Question: Create a folder named Nested IfLoopProgram 02. Copy the StatePark.java file from the Nested IF Program 02 folder. Paste it in the new folder. Open
Create a folder named Nested IfLoopProgram 02. Copy the StatePark.java file from the Nested IF Program 02 folder. Paste it in the new folder. Open the java file and edit the public line to StateParkLoop. Save the Java file as StateParkLoop.You will edit the program to add a loop and final totals.
b.Input consists of the camper’s name, residency code (Ror rfor Resident or Nor nfor Non-resident), and the number of days camping. Sample input is illustrated on page
2. Input will be entered from the keyboard. This program will process multiple records. Residency code must be defined as a char and both uppercase and lowercase should be tested.
c. This program must also contain a loop which will allow you to enter as many records as needed. The determination of whether to enter the loop should be in the form of a question.
d. The camping fees are determined as follows: If the camper is a state resident, the cost for the first seven days is 7.95 per day. After seven days, the cost drops to 5.95 per day. If the camper is a non-resident of the state, the cost is 9.95 per day, regardless of the number of days. If there is an error in the input record and the residency code contains neither an Ror r(resident) nor an Nor n (non-resident), the cost is 12.95 per day and the value UNKNOWN is printed for the residency.
e. Final totals must be calculated for the total campers, total resident campers, total non-resident campers, total unknown campers, total fees for resident campers, total fees for non-resident campers, total fees for unknown campers, and total fees for all campers.
f. The output will consist camper’s name, the residency works(Resident, Non-Resident, or Unknown), days camping, and the total camping fee. Display the fees with a dollar sign. The data displayed on the screen should be written on separate lines with a column heading identifying the data. There should be blank lines between the input data and the output data that is displayed on the screen. Sample output is shown on the next page. It shows what the output should look like when printed.
g. After all records have been processed, final totals will be printed. Final totals will be printed once. All fees should be printed with a dollar sign.
h. You decided on the appropriate data types and variable names. Named constants MUSTbe used in the program. This program should contain only one nested if statement.
here is the program i have to edit
import java.util.*;
public class StatePark
{
static double camping_cost (String name, char residency_code, int days)
{
double cost;
if (residency_code == 'R')
{
if (days > 7)
{
cost = (7 * 7.95) + ((days - 7) * 5.95);
}
else
{
cost = (days * 7.95);
}
}
else if (residency_code == 'N')
{
cost = 9.95 * days;
}
else
{
cost = 12.95 * days;
}
return cost;
}
public static void StatePark(String[]args)
{
double a;
// take user input
Scanner sc= new Scanner(System.in); //System.in is a standard input stream
System.out.print("Enter name: ");
String name= sc.nextLine();
System.out.print("Enter residency code: ");
char code = sc.next().charAt(0);
System.out.print("Enter number of days: ");
int days= sc.nextInt();
String c;
//camping cost
a = camping_cost (name, code, days);
//residency code as string
c = String.valueOf(code);
//given condition
if ((code!='R') && (code!='N'))
{
c ="UNKNOWN";
}
System.out.println("");
//output
System.out.println("Name: " + name);
System.out.println("Residency code: " + c);
System.out.println("Days: " + days);
System.out.println("Camping Cost: $" + a);
}
}
Step by Step Solution
3.31 Rating (154 Votes )
There are 3 Steps involved in it
NOTE you just need ti change these public static void StateParkStringargs to these public ... View full answer
Get step-by-step solutions from verified subject matter experts
