Question

In: Computer Science

This code has to be in java (I code in eclipse). Also these instructions have to...

This code has to be in java (I code in eclipse). Also these instructions have to be followed exactly because if not my output won't match the expected out ( this will be uploaded on zybooks).

Write a program that asks the user for their age in days. The program will compute the person's age in years (you can assume that all years have 365 days) and then prints one of the following messages:

  1. If the user is 1 year old or younger, print: "You are an infant"
  2. If the user is over 1 year old and 3 years old or younger, print: "You are a toddler"
  3. If the user is over 3 years old and 12 years old or younger, print: "You are a child"
  4. If the user is over 12 years old and 19 years old or younger, print: "You are a teenager"
  5. If the user is over 19 years old and 21 years old or younger, print: "You are a young adult"
  6. If the user is over 21 years old and 50 years old or younger, print: "You are an adult"
  7. If the user is over 50 years old but 65 years old or younger, print: "You are middle aged"
  8. If the user is over 65 years, print: "You are a senior citizen"

For example:

    If the user entered: 350, your program would output: You are an infant
    If the user entered: 800, your program would output: You are a toddler
    If the user entered, 1825, your program would output: You are a child
    If the user entered, 5475, your program would output: You are a teenager
    If the user entered, 7300, your program would output: You are a young adult
    If the user entered, 10950, your program would output: You are an adult
    If the user entered, 23725, your program would output: You are middle aged
    If the user entered, 25550, your program would output: You are a senior citizen
  

Your prompt to the user to enter the number of days must be:

    Enter an age in number of days:
  

Please note that your class should be named AgeLabel.

Solutions

Expert Solution

import java.util.Scanner;

public class AgeLabel {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter an age in number of days: ");
int days = sc.nextInt();
  
double year = days/360.0;
  
if(year <= 1)
System.out.print("You are an infant");
else if(year <= 3)
System.out.print("You are a toddler");
else if(year <= 12)
System.out.print("You are a child");
else if(year <= 19)
System.out.print("You are a teenager");
else if(year <= 21)
System.out.print("You are a young adult");
else if(year <= 50)
System.out.print("You are an adult");
else if(year <= 65)
System.out.print("You are middle aged");
}
}

// Hit the thumbs up if you are fine with the answer. Happy Learning!


Related Solutions

IN JAVA. I have the following code (please also implement the Tester to test the methods...
IN JAVA. I have the following code (please also implement the Tester to test the methods ) And I need to add a method called public int remove() that should remove the first integer of the array and return it at the dame time saving the first integer and bring down all other elements. After it should decrease the size of the array, and after return and save the integer. package ourVector; import java.util.Scanner; public class ourVector { private int[]...
I need code written in java for one of my projects the instructions are Write a...
I need code written in java for one of my projects the instructions are Write a program that interacts with the user via the console and lets them choose options from a food menu by using the associated item number. It is expected that your program builds an <orderString> representing the food order to be displayed at the end. (See Sample Run Below). Please note: Each student is required to develop their own custom menus, with unique food categories, items...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed:...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed: int id, String firstName, String middleName, String lastName, String email, String ssn, int age. The Person class should have getters and setters for all properties other than id. (You may use Eclipse to help you auto-generate these.) Person class should also have a getter for id Create a no-arg constructor for Person In addition to these getters and setters, Person should have the following...
When I wrote this code in the Eclipse program, I did not see a output .....
When I wrote this code in the Eclipse program, I did not see a output .. Why? _______ public class AClass { private int u ; private int v ; public void print(){ } public void set ( int x , int y ) { } public AClass { } public AClass ( int x , int y ) { } } class BClass extends AClass { private int w ; public void print() { System.out.println (" u + v...
Hi I have a java code for my assignment and I have problem with one of...
Hi I have a java code for my assignment and I have problem with one of my methods(slice).the error is Exception in thread "main" java.lang.StackOverflowError Slice method spec: Method Name: slice Return Type: Tuple (with proper generics) Method Parameters: Start (inclusive) and stop (exclusive) indexes. Both of these parameters are "Integer" types (not "int" types). Like "get" above, indexes may be positive or negative. Indexes may be null. Description: Positive indexes work in the normal way Negative indexes are described...
Code in java(eclipse) and please use simple codes Assignment Bigfoot has reportedly been seen in Southeast...
Code in java(eclipse) and please use simple codes Assignment Bigfoot has reportedly been seen in Southeast Texas forests. We have a drone searching for Bigfoot that can take pictures from the air. During a 24-hour period the drone can fly over the forest 3 times. On each flight we estimate Bigfoot will be in range of the camera on the drone for 2 minutes. The camera can take 10 photos per minute. We estimate there is a 30% chance Bigfoot...
I need this in java on textpad. There are two files, both have instructions in them...
I need this in java on textpad. There are two files, both have instructions in them on what to add in the code. They are posted below. public class MyArrayForDouble { double[] nums; int numElements; public MyArrayForDouble() { // Constructor. automatically called when creating an instance numElements = 0; nums = new double[5]; } public MyArrayForDouble(int capacity) { // Constructor. automatically called when creating an instance numElements = 0; nums = new double[capacity]; } public MyArrayForDouble(double[] nums1) { nums =...
Java homework problem: I need the code to be able to have a message if I...
Java homework problem: I need the code to be able to have a message if I type in a letter instead of a number. For example, " Please input only numbers". Then, I should be able to go back and type a number. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class LoginGui {    static JFrame frame = new JFrame("JFrame Example");    public static void main(String s[]) {        JPanel panel...
Java Programming. I'm writing this in an IDE called Eclipse. If you could also use comments...
Java Programming. I'm writing this in an IDE called Eclipse. If you could also use comments to help me understand the code / your way of thinking, I'd highly appreciate your efforts. This needs to use a for each loop, it will generates and return= an array of random 2-digit integers and it also needs to be printed out all on one line, separated by spaces. Program71: Write a program with a custom method that generates and returns an array...
This code must be written in Java. This code also needs to include a package and...
This code must be written in Java. This code also needs to include a package and a public static void main(String[] args) Write a program named DayOfWeek that computes the day of the week for any date entered by the user. The user will be prompted to enter a month, day, and year. The program will then display the day of the week (Sunday..Saturday). The following example shows what the user will see on the screen: This program calculates the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT