Question
Java - i have the program working here, I just need help aligning the columns correctly because they do not center correctly. For example, all
Java - i have the program working here, I just need help aligning the columns correctly because they do not center correctly. For example, all the names need to be in the far left (which is not happening as of this point)
import java.util.Scanner; import java.text.DecimalFormat;
public class HealthCheck {
public static void main(String[]args) {
//variables Scanner reader = new Scanner(System.in); DecimalFormat f = new DecimalFormat("##.0"); String name; int heartRate; int respiratoryRate; int height; int weight; int systolicPressure; int diastolicPressure; double BMI; int score;
System.out.println("Name\tHeart Rate\tResp Rate\tHeight\tWeight\tBMI\tBP\t\tScore");
//input while(reader.hasNext()){ name = reader.next(); heartRate = reader.nextInt(); respiratoryRate = reader.nextInt(); height = reader.nextInt(); weight = reader.nextInt(); systolicPressure = reader.nextInt(); diastolicPressure = reader.nextInt();
BMI = (((double)weight)* 0.453592d)/((((double)height)*0.0254) * (((double)height)*0.0254));
if(heartRate == 0 || respiratoryRate == 0 || height == 0 || weight == 0 || systolicPressure == 0 || diastolicPressure == 0) { System.out.println("Invalid record"); } else { System.out.print(name+"\t\t"); }
score = 1; if(heartRate >= 60 && heartRate <= 100){ score++; System.out.print(heartRate+"\t\t"); } else { System.out.print("!!"+heartRate+"\t\t");
} if(respiratoryRate >= 12 && respiratoryRate <= 18) { score++; System.out.print(respiratoryRate+"\t"); } else { System.out.print("!!"+respiratoryRate+"\t"); }
System.out.print(height+"\t"); System.out.print(weight+"\t"); System.out.printf(f.format(BMI)+"\t");
if((systolicPressure >= 90 && systolicPressure <= 120)&&(diastolicPressure >= 60 && diastolicPressure<=80)) { score++; System.out.print(systolicPressure+"/" +diastolicPressure+"\t\t"); } else { System.out.print("!!"+systolicPressure+"/" +diastolicPressure+"\t"); }
for(int i=0; i System.out.print("*"); } System.out.println(); } }
in1.dat:
Smith 70 15 72 168 110 70
Oracle 70 0 62 130 110 70
Switch 59 15 70 175 110 81
Trinity 100 11 68 140 110 70
Morpheus 60 19 72 175 110 70
Cypher 80 18 82 176 110 85
Dozer 80 15 82 177 89 70
Dujour 70 15 62 0 110 70
Tank 80 15 70 174 110 70
Neo 101 15 72 175 110 59
Jones 110 19 69 220 110 55
Apoc 80 15 62 130 121 70 ----------------------------
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