Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help with a Java Assignment
New Posts  All Forums:Forum Nav:

Help with a Java Assignment - Page 2

post #11 of 17
After glancing at a few of the specifications, I believe your while loop should look more like this:
Code:
while( true ) {             // infinite loop
   if (i > 5){ 
      break;                // this will exit you out of the loop
   }
   else if(i == 3) { 
      ++i;
      continue;             // this skips the remaining code in the loop
   }

   // the rest of your code
   ++i;
}

Although this is a really odd way of doing a while loop, I think the instructor is trying to demonstrate the uses of branching statements; possibly as a precursor for teaching recursion.
Edited by skkhai - 2/21/12 at 12:15pm
post #12 of 17
Thread Starter 
Quote:
Originally Posted by hometoast View Post

Yeah, it doesn't help that the assignment is written almost incoherently.
Did you start on the "the stuff inside the while loop" yet?
Quote:
Originally Posted by hometoast View Post

I just read this assignment again and I want to backhand your teacher.

So it's not just me making excuses for myself...he is making it harder than need be to understand correct?

I thought so, because when I see it here in my help threads, it clicks almost immediately, yet I'll read the lessons 3 times and still be all confused.gif

And no, I haven't had a chance to do anything else, this server migration at work is killing me.
 
Work Lappy
(4 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i7 960 P6T NVIDIA GeForce GTX 560 Ti NVIDIA GeForce GTX 560 Ti 
RAMRAMRAMHard Drive
G.Skill DDR3 G.Skill DDR3 G.Skill DDR3 OCZ Vertex 3 SSD 
Hard DriveOptical DriveCoolingOS
WD Backup Lite-On DVD Corsair H80 Windows 7 Pro 
KeyboardPowerCaseMouse
Logitech G15 v2 OCZ ModXStream Pro 700W Antec 300 Logitech g5 
Mouse PadAudio
Ratpad Razer Barracuda AC-1 
CPUMotherboardGraphicsRAM
Intel Core i5 0JGC48 Intel(R) HD Graphics Family Micron Technology  
  hide details  
Reply
 
Work Lappy
(4 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i7 960 P6T NVIDIA GeForce GTX 560 Ti NVIDIA GeForce GTX 560 Ti 
RAMRAMRAMHard Drive
G.Skill DDR3 G.Skill DDR3 G.Skill DDR3 OCZ Vertex 3 SSD 
Hard DriveOptical DriveCoolingOS
WD Backup Lite-On DVD Corsair H80 Windows 7 Pro 
KeyboardPowerCaseMouse
Logitech G15 v2 OCZ ModXStream Pro 700W Antec 300 Logitech g5 
Mouse PadAudio
Ratpad Razer Barracuda AC-1 
CPUMotherboardGraphicsRAM
Intel Core i5 0JGC48 Intel(R) HD Graphics Family Micron Technology  
  hide details  
Reply
post #13 of 17
Quote:
Originally Posted by Krunk_Kracker View Post

So it's not just me making excuses for myself...he is making it harder than need be to understand correct?
I thought so, because when I see it here in my help threads, it clicks almost immediately, yet I'll read the lessons 3 times and still be all confused.gif
And no, I haven't had a chance to do anything else, this server migration at work is killing me.

skkhai makes a good point though. it's unorthodox, but you it does do a good demonstration of showing the difference between a break and a continue.
RAWR
(13 items)
 
Home Server
(11 items)
 
 
CPUMotherboardGraphicsRAM
i7-4790k msi z97 gaming 7 gtx 760 4gb 32GB GSkill  
Hard DriveHard DriveCoolingOS
Kingston HyperX 3K 120GB SSD Hitachi 2TB Cooler Master Hyper 212+ Windows 8.1 Pro 
MonitorKeyboardPowerCase
Vizio M492-b2 Logitech Wireless  Corsair HX620 NZXT Phantom White 
Mouse
Logitech Wireless 
  hide details  
Reply
RAWR
(13 items)
 
Home Server
(11 items)
 
 
CPUMotherboardGraphicsRAM
i7-4790k msi z97 gaming 7 gtx 760 4gb 32GB GSkill  
Hard DriveHard DriveCoolingOS
Kingston HyperX 3K 120GB SSD Hitachi 2TB Cooler Master Hyper 212+ Windows 8.1 Pro 
MonitorKeyboardPowerCase
Vizio M492-b2 Logitech Wireless  Corsair HX620 NZXT Phantom White 
Mouse
Logitech Wireless 
  hide details  
Reply
post #14 of 17
so did you ever get this resolved??? i have the same problem n im badly stuck:mad:
post #15 of 17
Quote:
Originally Posted by Urwashi View Post

so did you ever get this resolved??? i have the same problem n im badly stuck:mad:

What do you need help with? Post the question and the code you have come up with, please.
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
post #16 of 17
(x) Next (still inside the while loop), use the following formula to compute the temperature of each of the 12 months of years 1, 2, 4 and 5. Use a for loop to loop over the months in a given year.
Year i = 1:
Month j = 1, 2, ... 12
Note: (A) and (B) below, taken together will be called "Equation 1".
(A) Winter Months: j = 1, 2, 11 and 12: Temperature = j + 3
(B) Other Months: j = 3, 4, 5, .., 9, 10: Temperature = 5j + 7

Note: Use a logical expression to differentiate between Winter and Other Months, in conjunction with the ?: operator, all in one single statement to compute the temperature for a month j using Equation 1.

1st year, so ANNUAL_INCREASE doesn't apply, but uncertainty does. In the next line, increase Temperature by Uncertainty percent to display the final temperature, for each month.

Example: If Temperature calculated above is 45.0, and uncertainty is 2.1 percent, then final Temperature is 45.0 * (1.0 + 2.1/100) = 45.945. Only the integer part is to be displayed (decimal part truncated), so it should show 45 as the value in this case.
Years: i = 2, 4, 5
First calculate Temperature using Equation 1. Next, find the increases to apply to that value. Temperature increase per year: ANNUAL_INCREASE (degrees) - same increase applies to each month of a year. Use the Year i and ANNUAL_INCREASE in an expression to figure the exact increase that would apply for that year.

Uncertainty percent applies to the value obtained after the ANNUAL_INCREASE.

Example: If temperature for a month is 45.0 using Equation 1, and it is Year 4, so you are 3 years away from Year 1, which means 3 annual increases on top of each other. Each annual increase is 1.0 degree (= ANNUAL_INCREASE), so for 3 years beyond Year 1, you need 1.0 + 1.0 + 1.0 = 3.0 degrees from the base value (45.0), so temp for Year 4 would be 45.0 + 3.0 = 48.0.

Next, you apply the uncertainty percent on this modified value (48.0) as applicable for year 4 (7.4 percent). So the temperature for that month in Year 4 becomes: 48.0 X (1.0 + 7.4/100) = 51.552. Value displayed will be integer part only (decimal part truncated), so it should display 51 in this example.

Inside the 'for loop', concatenate temperature values for all 12 months with spaces in between, assign it to 'result' and display in one line along with the Year i. Repeat for years 1, 2, 4 and 5. Try to align the output with the Month headers by maniupulating the blank space in between.
(xi) A sample output session is shown below (your output needs to match with this):


C:\Java\Lesson4\assign41>javac Weather.java

C:\Java\Lesson4\assign41>java Weather

Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 4 5 22 27 32 37 42 47 53 58 14 15
2 5 6 23 29 34 39 44 50 55 60 15 16
4 7 8 26 32 37 42 48 53 59 64 18 19
5 8 9 28 33 39 44 49 55 60 66 19 20
C:\Java\Lesson4\assign41>


I need help on these step... if any one could you please help me,.
post #17 of 17
I have done so far these coding need help for last step..

public class Weather{

public static void main(String[] args) {
int i = 1;
double temp = 0.0;
final double ANNUAL_INCREASE = 1.0;
double uncertainty = 0.0;
String result = " ";

System.out.println(" Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");

while(true)
{
if (i > 5) break;
System.out.println(" "+i);
i++;
{
if(i==3){i++;continue;}
}
}
switch(i)
{
case 1 :
uncertainty = 2.1;
break;
case 2 :
uncertainty = 4.3;
break;
case 4 :
uncertainty = 7.4;
break;
case 5 :
uncertainty = 8.6;
break;
default:
uncertainty = 0;
break;
}
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help with a Java Assignment