Question

In: Computer Science

JAVA PROGRAM The Florida Dental Association needs a simple program to record what teeth the members...

JAVA PROGRAM

The Florida Dental Association needs a simple program to record what teeth the members of Florida families have. Different Floridians have different numbers of different types of teeth (the program must use this simplified categorization of types of teeth):

  • Biting teeth (the 'B' teeth)
  • Chewing teeth (the 'C' teeth)
  • Missing teeth (the 'M' teeth)

The program must record the teeth for one Florida family. When it starts the program asks how many people there are in the family (maximally 5), then for each family member gets their name, a string of tooth types for the uppers (maximally 10 teeth including missing teeth), and a string a tooth types for the lowers (maximally 10 teeth), e.g., the string "CMCBBBMCCM" would represent 10 teeth (of which three are missing). The names are recorded in an array of strings. The tooth information is recorded in a three dimensional array of characters, where each plane corresponds to a person, there are two rows for uppers and lowers, and each row has a column for each tooth. Once the information is recorded the program must offer a menu of four options:

  1. Print the family's teeth record.
  2. Extract a tooth (with a check that there is something there to remove).
  3. Report the family's root canal indices, which are the roots of the quadratic equation Bx2 + Cx - M, where B, C, and M are the family's numbers of those types of teeth.
  4. Exit (with a smile)

The program must be reasonably idiot proof:

  • Menu options must be accepted in upper and lower case.
  • Tooth letters must be accepted in upper and lower case.
  • All input must be checked to be in range, and if not the user must be asked to input again.
  • You may assume that numeric input will be syntactically correct.

Here's what a sample run should look like (with the keyboard input shown in italics) ...

Welcome to the Floridian Tooth Records
--------------------------------------
Please enter number of people in the family : -3
Invalid number of people, try again         : 7
Invalid number of people, try again         : 3
Please enter the name for family member 1   : Henrietta
Please enter the uppers for Henrietta       : ABCDEFGHIJ
Invalid teeth types, try again              : BBBCMCBBBMCCMBBB
Too many teeth, try again                   : CMCBBBMCCM
Please enter the lowers for Henrietta       : CCMBBMCC
Please enter the name for family member 2   : Stanley
Please enter the uppers for Stanley         : mbbm
Please enter the lowers for Stanley         : ccMMcc
Please enter the name for family member 3   : Raul
Please enter the uppers for Raul            : CCBbbcC
Please enter the lowers for Raul            : ccbBBCC

(P)rint, (E)xtract, (R)oot, e(X)it          : T
Invalid menu option, try again              : p

Henrietta
  Uppers:  1:C  2:M  3:C  4:B  5:B  6:B  7:M  8:C  9:C 10:M
  Lowers:  1:C  2:C  3:M  4:B  5:B  6:M  7:C  8:C
Stanley
  Uppers:  1:M  2:B  3:B  4:M
  Lowers:  1:C  2:C  3:M  4:M  5:C  6:C
Raul
  Uppers:  1:C  2:C  3:B  4:B  5:B  6:C  7:C
  Lowers:  1:C  2:C  3:B  4:B  5:B  6:C  7:C

(P)rint, (E)xtract, (R)oot, e(X)it          : E
Which family member                         : Melanie
Invalid family member, try again            : stanley
Which tooth layer (U)pper or (L)ower        : M
Invalid layer, try again                    : u
Which tooth number                          : 27
Invalid tooth number, try again             : 4
Missing tooth, try again                    : 2

(P)rint, (E)xtract, (R)oot, e(X)it          : P

Henrietta
  Uppers:  1:C  2:M  3:C  4:B  5:B  6:B  7:M  8:C  9:C 10:M
  Lowers:  1:C  2:C  3:M  4:B  5:B  6:M  7:C  8:C
Stanley
  Uppers:  1:M  2:M  3:B  4:M
  Lowers:  1:C  2:C  3:M  4:M  5:C  6:C
Raul
  Uppers:  1:C  2:C  3:B  4:B  5:B  6:C  7:C
  Lowers:  1:C  2:C  3:B  4:B  5:B  6:C  7:C

(P)rint, (E)xtract, (R)oot, e(X)it          : R
One root canal at     0.40
Another root canal at -2.07

(P)rint, (E)xtract, (R)oot, e(X)it          : X

Exiting the Floridian Tooth Records :-)

Solutions

Expert Solution

Code


import java.util.Scanner;


public class Main {
static Scanner scnr=new Scanner(System.in);
final static int MAX_PERSON=5;
final static int MAX_TEETH=10;
public static void main(String[] args) {
  
String names[];
char teeth[][][];
int num_person;
char choice;
System.out.print("Please enter number of people in the family :");
num_person=scnr.nextInt();
while(num_person<0 || num_person>MAX_PERSON)
{
System.out.print("Invalid number of people, try again : ");
num_person=scnr.nextInt();
}
names=new String[num_person];
teeth=new char[num_person][2][];
getInput(names,teeth);
  
do
{
choice=menu();
switch(choice)
{
case 'P':
printInfo(names,teeth);
break;
case 'E':
ExtractTooth(names,teeth);
break;
case 'R':
rootCanalIndices(teeth);
case 'X':
break;
}
}while(choice!='X');
System.out.println("\nExiting the Floridian Tooth Records :-)");
}
//function that will get naame and teeth
private static void getInput(String[] names, char[][][] teeth)
{
String t;
for(int i=0;i<names.length;i++)
{
System.out.print("Please enter the name for family member "+(i+1)+" : ");
names[i]=scnr.next();
System.out.print("Please enter the uppers for "+names[i]+" : ");
t=scnr.next();
t=t.toUpperCase();
while(!isValidTeeths(t))
{
t=scnr.next();
t=t.toUpperCase();
}
teeth[i][0]=t.toCharArray();
System.out.print("Please enter the lowers for "+names[i]+" : ");
t=scnr.next();
t=t.toUpperCase();
while(!isValidTeeths(t))
{
t=scnr.next();
t=t.toUpperCase();
}
teeth[i][1]=t.toCharArray();
}
}
//this fucntion will validate the teeth input if its valid then return true otherwise false
private static boolean isValidTeeths(String t) {
if(t.length()>MAX_TEETH)
{
System.out.print("Too many teeth, try again : ");
return false;
}
for(int i=0;i<t.length();i++)
{
if(t.charAt(i)=='M' || t.charAt(i)=='C' || t.charAt(i)=='B')
continue;
else
{
System.out.print("Invalid teeth types, try again :");
return false;
}
}
return true;
}
//functon that will print menu and ask user choice and validate it return the user choice
private static char menu() {
char choice;
System.out.print("\n(P)rint, (E)xtract, (R)oot, e(X)it :");
choice=scnr.next().charAt(0);
choice=Character.toUpperCase(choice);
while(!(choice=='P' || choice=='E' || choice=='R' || choice=='X'))
{
System.out.print("Invalid menu option, try again : ");
choice=scnr.next().charAt(0);
choice=Character.toUpperCase(choice);
}
return choice;
}
//this function will print the info of evry member
private static void printInfo(String[] names, char[][][] teeth)
{
System.out.println("");
for(int i=0;i<names.length;i++)
{
System.out.println(names[i]);
System.out.print(" Uppers: ");
for(int j=0;j<teeth[i][0].length;j++)
{
System.out.print((j+1)+":"+teeth[i][0][j]+" ");
}
System.out.print("\n Lowers: ");
for(int j=0;j<teeth[i][1].length;j++)
{
System.out.print((j+1)+":"+teeth[i][1][j]+" ");
}
System.out.println("");
}
  
}
//this function will find the name provided by the user and return it index in array if it will in array oterwise return -1
public static int findMember(String[] names, String findName)
{
for(int i=0;i<names.length;i++)
if(names[i].equalsIgnoreCase(findName))
return i;
return -1;
}
//this function exteact the tooth of memeber
private static void ExtractTooth(String[] names, char[][][] teeth) {
String name;
char layer;
int toothNumber;
int upperLower;
System.out.print("Which family member : ");
name=scnr.next();
int pos=findMember(names, name);
while(pos<0)
{
System.out.print("Invalid family member, try again : ");
name=scnr.next();
pos=findMember(names, name);
}
System.out.print("Which tooth layer (U)pper or (L)ower : ");
layer=scnr.next().charAt(0);
layer=Character.toUpperCase(layer);
while(!(layer=='U' || layer=='L'))
{
System.out.print("Invalid layer, try again : ");
layer=scnr.next().charAt(0);
layer=Character.toUpperCase(layer);
}
if(layer=='U')
upperLower=0;
else
upperLower=1;
System.out.print("Which tooth number : ");
toothNumber=scnr.nextInt();
boolean valid=true;
while(true)
{
if(toothNumber<0 || toothNumber>MAX_TEETH)
{
System.out.print("Invalid tooth number, try again : ");
toothNumber=scnr.nextInt();
continue;
}
if(teeth[pos][upperLower][toothNumber-1]=='M')
{
System.out.print("Missing tooth, try again : ");
toothNumber=scnr.nextInt();
continue;
}
teeth[pos][upperLower][toothNumber-1]='M';
break;
}
}
//this funciton will print root canal indeices
private static void rootCanalIndices(char[][][] teeth)
{
int B=0,M=0,C=0;
for(int i=0;i<teeth.length;i++)
{
for(int j=0;j<teeth[i][0].length;j++)
{
if(teeth[i][0][j]=='M')
M++;
else if(teeth[i][0][j]=='C')
C++;
else
B++;
}
for(int j=0;j<teeth[i][1].length;j++)
{
if(teeth[i][1][j]=='M')
M++;
else if(teeth[i][1][j]=='C')
C++;
else
B++;
}
}
double determinant = C * C - 4 * B * (-M);
double root1, root2;
if(determinant > 0) {
root1 = (-C + Math.sqrt(determinant)) / (2 * B);
root2 = (-C - Math.sqrt(determinant)) / (2 * B);
System.out.printf("One root canal at %.2f%n",root1);
System.out.printf("Another root canal at %.2f%n",root2);
}
// Condition for real and equal roots
else if(determinant == 0) {
root1 = root2 = -C / (2 * B);
System.out.printf("One root canal at %.2f%n",root1);
}
}
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

In 2013, according to the American Dental Association, 50% of adults floss their teeth daily. Wondering...
In 2013, according to the American Dental Association, 50% of adults floss their teeth daily. Wondering if the percentage is less today, a recent Gallup poll was conducted and found that 436 out of 960 adults floss daily. Perform a hypothesis test at the ? = 0.05 level of significance. Is there sufficient evidence to conclude that the percentage of Americans who floss today is less than 50%? 1. what is the test statistic? 2. what is the p-value 3....
Needs to be in JAVA. Write a Java program that accepts the total amount of cars...
Needs to be in JAVA. Write a Java program that accepts the total amount of cars sold and total sales amount of a car salesperson for a given month. The salesperson’s paycheck is computed as follows: a. Every sales person gets 10% (commission) of total sales b. Sales totals greater than $50,000 get 5% of total sales amount c. 8 or more cars sold earns the salesperson an extra 3% Please remove 30% (taxes) of the gross pay and list...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
Java Write a program to record the GPAs of a class and find the percentage of...
Java Write a program to record the GPAs of a class and find the percentage of students in each GPA. The program first allows the user to enter the number of students enrolled in the class, and then to enter the GPA of all students one by one. For each student, the input must be between 1 and 4 inclusively. Otherwise, the software displays a message as “Invalid number!” and asks for a new GPA for the same student Enter...
The client needs this program written in Java. Your team is tasked to create a program...
The client needs this program written in Java. Your team is tasked to create a program that converts Fahrenheit to Celsius. Fahrenheit temperature of 87.6 degrees. Convert it to Celsius, and display the temperature in both units. Your output should look similar to the following: Fahrenheit Temperature: 87.6 Celsius Temperature: 30.88
For this assignment, you will apply what you learned in analyzing a simple Java™ program by...
For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program. The Java™ program you write should do the following: Display a prompt on the console asking the user to type in his or her first name Construct the greeting string "Hello, nameEntered!" Display the constructed greeting on the console Complete this assignment by doing the following: Download and unzip the linked zip file. Add comments to the code by...
For this assignment, you will apply what you learned in analyzing a simple Java™ program by...
For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program that creates and accesses an array of integers. The Java™ program you write should do the following: Create an array to hold 10 integers Ask the user for an integer. Note: This code has already been written for you. Populate the array. Note: The first element should be the integer input by the user. The second through tenth elements...
in a gui ' in java write a program that draws equal a simple fence with...
in a gui ' in java write a program that draws equal a simple fence with vertical, spaced slats backed by two boards. Behind the fence show a simple house support Make sure the in the und. house is visible between the slats in the fence.
I want to write this program in java. Write a simple airline ticket reservation program in...
I want to write this program in java. Write a simple airline ticket reservation program in java.The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit...
Develop a java program with a class named friend with data members like name, phno and...
Develop a java program with a class named friend with data members like name, phno and hobby. Use Parameterized constructor to create two friend objects and invoke checkhobby method which takes only one parameter, to find whether they have same hobby or different hobbies
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT