473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

can someone please double check my results or outcome

this is a population problem that asks for number of starting organisms, the percent increase per day and the number of days allowed to grow. this program is done and fully compiled but i feel like im missing something. can someone double check my equations. this is the entire code. Thanks much

Expand|Select|Wrap|Line Numbers
  1. //Programmer: David 
  2. //CS 75 TTh
  3. //Assignment #4 Programming Challenge "Population"
  4. //Due: 9-29-15
  5. //This program will allow the user to predict the size of
  6. //the population of an organism by using loops. In addition, the results should
  7. //be stored in an output file and printed.
  8.  
  9.  
  10.  
  11.  
  12. import java.util.Scanner; //needed for the Scanner class
  13. import java.io.*; //needed for the File and IOException
  14.  
  15. public class Population
  16. {
  17.     public static void main (String [] args) throws IOException
  18.     {
  19.         double numOfOrganisms; //store user input for starting number of organisms
  20.         double dailyIncrease; //store user input for percent increase per day
  21.                               //this needs to be converted to a percent by dividng by 100
  22.         double startValue; //store for initial number of organisms and daily increase
  23.         double days; //store user input for the number of days organism will multiply
  24.  
  25.  
  26.         Scanner keyboard = new Scanner (System.in); //create object for user input
  27.  
  28.         //ask the user for starting amount of organisms
  29.         System.out.print("Enter the amount of starting organisms: ");
  30.         numOfOrganisms = keyboard.nextInt();
  31.  
  32.         //determine if amount of organisms is valid choice using while loop
  33.         while (numOfOrganisms < 2)
  34.         {
  35.             System.out.println("Invalid input for starting organisms.");
  36.             System.out.print("Please enter 2 or more starting organisms: ");
  37.             numOfOrganisms = keyboard.nextInt();
  38.             System.out.print("You entered a total of " + numOfOrganisms + " organisms\n");
  39.         }
  40.  
  41.         //ask the user for percent population increase, will convert to percentage later
  42.         System.out.print("Enter the average daily percent population increase: ");
  43.         dailyIncrease = keyboard.nextDouble();
  44.  
  45.         //determine if daily increase is valid using while loop
  46.         while (dailyIncrease <= 0)
  47.         {
  48.             System.out.println("Invalid input for daily increase.");
  49.             System.out.print("Please enter a non-negative number for daily increase: ");
  50.             dailyIncrease = keyboard.nextInt();
  51.             System.out.println("You entered a total of " + dailyIncrease + " percnet daily increase.");
  52.         }
  53.  
  54.         //ask the user number of days
  55.         System.out.print("Enter the number days for the population to grow: ");
  56.         days = keyboard.nextInt();
  57.  
  58.         //determine if days is valid using while loop
  59.         while (days <= 1)
  60.         {
  61.             System.out.println("Invalid input for days entered.");
  62.             System.out.print("Please enter 2 or more for total days: ");
  63.             days = keyboard.nextInt();
  64.             System.out.println("You entered a total of " + days + " days.");
  65.         }
  66.  
  67.         //Open the file and create PrintWriter object
  68.         PrintWriter outputFile = new PrintWriter("PopulationList.txt");
  69.  
  70.         //design file header for displaying final results
  71.         outputFile.println("Days\t\t Total Population");
  72.         outputFile.println("*********************************");
  73.  
  74.         //store result of initial number of organisms multiplied by daily increase
  75.         //also divided by 100 to convert to percentage
  76.         startValue = (dailyIncrease/100)*(numOfOrganisms);
  77.  
  78.         //use for loop to compute each result based on number of days
  79.         for ( int i = 0; i < days; i++)
  80.         {
  81.  
  82.             System.out.println(i+1 + "\t\t " + numOfOrganisms);
  83.             outputFile.println(i+1 + "\t\t " + numOfOrganisms);
  84.             numOfOrganisms = numOfOrganisms + startValue;
  85.  
  86.  
  87.  
  88.         }
  89.  
  90.         //Close the file
  91.         outputFile.close();
  92.         System.out.println("Data written on the file.");
  93.  
  94.     }
  95. }
  96.  
  97. /*
  98. C:\Users\Matt\Documents\Java>java Population
  99. Enter the amount of starting organisms: 11
  100. Enter the average daily percent population increase: 25
  101. Enter the number days for the population to grow: 10
  102. 1                11.0
  103. 2                13.75
  104. 3                16.5
  105. 4                19.25
  106. 5                22.0
  107. 6                24.75
  108. 7                27.5
  109. 8                30.25
  110. 9                33.0
  111. 10               35.75
  112. Data written on the file.
  113. */
Sep 24 '15 #1
7 1580
Rabbit
12,516 Expert Mod 8TB
I feel like im missing something
Why do you feel that way? You must see something off to feel that way. It's hard for us just guess what's wrong based off something as vague as a feeling. If it's compiling and executing and producing expected output, then there's nothing wrong. If it's not doing one of those 3 things correctly, you need to explain which one of the 3 isn't working correctly and explain the symptoms of what's wrong.

Also, please use code tags when posting code or formatted data.
Sep 24 '15 #2
ok sorry dude. i just wanted someone to double check my equations and maybe see any hiccups in my while loops. im just beginning here.
Sep 24 '15 #3
Rabbit
12,516 Expert Mod 8TB
No need to be sorry, it's just most of the volunteers on the site don't have time to check every line of code. And while someone might come along with enough time to do that, you're more likely to get an answer if you have something specific you want them to check. Like an error code or erroneous output.

Since this code looks like it's for a class, the teacher probably gave you sample inputs and outputs to check your code against.

It looks like you are able to compile and run the code so there's nothing "wrong" with the code in that sense. The only thing you need to do now is to check your outputs against the sample inputs/outputs provided by the teacher. If those match up, then you can rest easy.
Sep 24 '15 #4
i just want someone to double check my code its not like im asking anyone to do the program for me.
Sep 24 '15 #5
ok Rabbit sounds good. i feel like this program is good i hope lol. thanks for your time.
Sep 24 '15 #6
Rabbit
12,516 Expert Mod 8TB
And that's fine if that's what you need. Hopefully someone will have the time to do that for you. You are missing one piece of information though if you need them to fully check the code, the expected output given certain inputs.

Someone can check that your code compiles and runs. But without that last piece of information, they can't be sure that your program is running as expected because they don't know what to expect.

It sounds like you already have compilation and execution checked. If you post that last piece of information, someone can check the last piece of the puzzle.
Sep 24 '15 #7
Rabbit
12,516 Expert Mod 8TB
I had some time to look at the results. Unfortunately, I can't tell you whether or not they are right with 100% certainty. This is because we are missing the information that I mentioned in post #7.

I can, however, make guesses. But don't take my guesses as definitive answers until you can check it against the full requirements for the assignment.

As far as straight math goes, the formula you coded and the results coming out of that formula are correct.

If the assignment is to code linear growth, then your output is correct.

If the assignment is to code exponential growth, then your output is incorrect.

If I had to guess what your assignment is, I would guess that it is to code exponential growth. In which case, the growth accelerates with each generation. While there are situations where you do want to code linear growth, they are rare.

If you do confirm that you need exponential growth, then you need to recalculate your growth amount (startValue) at each iteration of the loop.
Sep 25 '15 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rtritell | last post by:
I dont get whats wrong with this <html> <head> <title>Random Mad Lib!</title> <script language="JavaScript"> <!-- Hide
3
by: opt_inf_env | last post by:
Hello, In some examples of a PHP implementation I saw the following: if ( isset(x) and x==12) I do not understand what for before to check whether some variable has some value one need to check...
2
by: Skybuck Flying | last post by:
Hi, This is a somewhat cleaned up version 0.02 of the nrand48() routine. There are still a few issues: This code needs brackets but where ? X = (uint64) xsubi << 32 | (uint32) xsubi << 16...
8
by: Sandy | last post by:
I have two tables, tblPost - (Cols PostID, TopicID, UserID, Question, PostMsg and PostDT) and tblTopic - (Cols TopicID, Topic). I am trying to get tblPost.Question and tblPost.PostDT into...
10
by: Miro | last post by:
I wanted certain text boxes ( only certain ones ) to always be Trim'd so that spaces are not in the begining, nor the end of the text entered. I created my own "Handle ?" - i hope thats the...
4
by: garyusenet | last post by:
The following code was supplied by a kind poster as a solution to a problem i was having. But it's not quite working. I have commented the code myself below. Can you please read my comments to make...
11
by: aisling.cronin | last post by:
Hi I am using ctime to convert the following string 1144412677847 .... Please could some one to double check if they get the same result as me (The Time is Sun Nov 02 09:11:51 2031). It seems...
3
by: shapper | last post by:
Hello, I have two tables: Polls and Options: Poll PollID, Question Options OptionID, PollID, Answer I want to select a Poll given its ID and all Options associated to it. Options should...
1
by: smepperson | last post by:
Can anyone help explain this in simple terms. My textbok is useless... Have to code a Loop that will check if a name you are adding to a CheckedListBox has already been entered , if not add name...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.