that I wanted to import the scanner to be able to take user input. So that the user

could input his/her age.

I wanted to do it like this:

Code :

import java.util.Scanner;
public class Tutorial {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner age = new Scanner(System.in);
System.out.print("Enter Your Age: ");
System.out.println(age.next());
if (age == 18) {
System.out.println("You're good to go!");
}
else if (age < 18) {
System.out.println("Grow up!");
}
age.close();
}
}

This is how I would have written it in C++. But in Java it must be another way to write this.

How do you remake the code to a full working Java code that can compile if it isn't this way? ]]>

Program 1

Write a program that collects and processes data about quarterly rainfall for one year. Your program should ask the user to enter rain fall amounts for each of the four quarters in the year. You must use a looping construct to collect the input for one quarter at a time until all four quarters’ data is collected. For your program’s output, you should name which quarter (i.e. Quarter 1, Quarter 2, Quarter 3, or Quarter 4) had the most rainfall, which quarter had the least rainfall, the average rainfall for the entire year, and the total rainfall for the entire year. All output should be displayed with meaningful descriptions.

Program 2

Modify program 1 so that it will handle multiple years of rainfall data. The user should be asked at runtime to supply the actual number of years they want to enter in the program for evaluation. In addition to the output specified in program 1 for each individual year, program 2 should output the year (i.e. Year 1, Year 2, etc.) with the most total rainfall and the year with the least total rainfall. All output should be displayed with meaningful descriptions. You are required to use a nested looping construct for this program.

Sample output: (Your program should work properly with all positive data)

How many year's rainfall amounts would you like to enter: 2

ÏÏ ÏEnter data for year 1

Ï Enter the rainfall for quarter 1: 4

Ï Enter the rainfall for quarter 2: 2

Ï Enter the rainfall for quarter 3: 8

Ï Enter the rainfall for quarter 4: 6

ÏÏÏ

ÏÏ Ï Quarter 3 had the most rainfall with 8.0 inches

ÏÏ Ï Quarter 2 had the least rainfall with 2.0 inches

ÏÏ Ï The total rainfall for year 1 was 20.0 inches

ÏÏ Ï The average quarterly rainfall for year 1 was 5.0 inches

ÏÏ Ï

ÏÏ ÏEnter data for year 2

Ï Enter the rainfall for quarter 1: 3.1

Ï Enter the rainfall for quarter 2: 9.1

Ï Enter the rainfall for quarter 3: 5.1

Ï Enter the rainfall for quarter 4: 1.1

ÏÏÏ

ÏÏ Ï Quarter 2 had the most rainfall with 9.1 inches

ÏÏ Ï Quarter 4 had the least rainfall with 1.1 inches

ÏÏ Ï The total rainfall for year 2 was 18.4 inches

ÏÏ Ï The average quarterly rainfall for year 2 was 4.6 inches

ÏÏÏ

Ï ÏYear 1 had the most rainfall with 20.0 inches

ÏÏ ÏYear 2 had the least rainfall with 18.4 inches

ÏÏÏ

--- Update ---

Can use for loop, nested for loop, while, do while, if, if else if, if else and switch.

Cannot use arrays. ]]>

Class test; {

public static void main (String args[])

{

int x = 30,y;

y = (x >>= 1);

System.out.println("y= "+y);

}

}

i understand what >> and >>> are, but this symbols below I don't understand what they do:

++

- -

+=

-=

*=

/=

%=

&=

|=

^=

>>=

<<=

>>>=

<<<=

x&=y

x|=y

x^=y

^ is the symbol for XOR but what is it?

Thanks :) ]]>

I try a few hours to think about algorithm..but cant find.

The outer frame is no problem.

If n is even then n / 2 else N / 2 + 1

thank you

My Monthly Payment and Total Payments are not adding up any ideas?

Code :

package loanslab5;
import java.util.Scanner;
public class LOANSLAB5
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Loan Amount: ");
double loanAmount=in.nextDouble();
System.out.print("Numer of Years: ");
int years=in.nextInt();
double annualInterestRate = 5;
double monthlyInterestRate = annualInterestRate / 1200;
double monthlyPayment = loanAmount * monthlyInterestRate /
(1-1 / Math.pow(1 + monthlyInterestRate, years * 12));
double totalPayment = monthlyPayment * 12 * years;
double i = 5.0;
int lastMonth = years * 12;
int month = 1;
while ( i <= 8.0)
{
monthlyPayment = (int) (monthlyPayment * 100) / 100.0;
totalPayment = (int) (totalPayment * 100) / 100.0;
i +=0.125;
System.out.println("Interest Rate Monthly Payment Total Payment");
System.out.println(i + "% $" + monthlyPayment + " $" + totalPayment);
}
}
}

My Output

Code :

run:
Loan Amount: 10000
Numer of Years: 5
Interest Rate Monthly Payment Total Payment
5.125% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
5.25% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
5.375% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
5.5% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
5.625% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
5.75% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
5.875% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
6.0% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
6.125% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
6.25% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
6.375% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
6.5% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
6.625% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
6.75% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
6.875% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
7.0% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
7.125% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
7.25% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
7.375% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
7.5% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
7.625% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
7.75% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
7.875% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
8.0% $188.71 $11322.74
Interest Rate Monthly Payment Total Payment
8.125% $188.71 $11322.74
BUILD SUCCESSFUL (total time: 4 seconds)