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)

Im a beginner in java..

Code Java:

public class Run{
public static void main(String[] args)
{
ArrayExercise array = new ArrayExercise();
// string array
String[] StringArray = new String[5];
StringArray[0] = "A";
StringArray[1] = "B";
StringArray[2] = "C";
StringArray[3] = "A";
StringArray[4] = "A";
// loop for printing out ALL letters in the array
for (int i=0; i < StringArray.length; i++)
{
{
System.out.println("" + StringArray[i]);
}
}
// for loop for how many times A appears
for (String elements: StringArray)
{
{
System.out.println("" + elements);
}
}
System.out.println("No of times A appears : " + StringArray.length);
}
}

Code java:

public String mixString(String a, String b) {
String result = "";
if (a.length() < b.length())
{
int i;
for (i = 0; i < a.length(); i++)
{
result = result + a.charAt(i);
result = result + b.charAt(i);
}
return result + b.substring(i);
}
if (a.length() > b.length())
{
int i;
for (i = 0; i < b.length(); i++)
{
result = result + a.charAt(i);
result = result + b.charAt(i);
}
return result + a.substring(i);
}
if (a.length() == b.length())
{
int i;
for (i = 0; i < a.length(); i++)
{
result = result + a.charAt(i);
result = result + b.charAt(i);
}
return result;
}
}

The above code gives an error that claims that the method is missing a return statement. I changed the code to the format if...else if...else, and the changed format to the extended if-else statements fixed the error. Why? In the above code, all of the possibilities are given (a is longer than b, b is longer than a, or a is equal in length to b), so why if there a purportedly missing return statement? ]]>

The instructions say to use Select/Case statements instead of if statements.

Here is my If-else statement code:

Thanks for any help!

Code :

import java.util.Scanner;
import javax.swing.JOptionPane;
public class Area {
public static void main(String args [])
{
double Area;
String ShapeString = JOptionPane.showInputDialog(null, "Enter C for Circle, S for square, or R for rectangle", "Shape Selection", JOptionPane.QUESTION_MESSAGE);
if (ShapeString.equals("C")){
String radiusString = JOptionPane.showInputDialog(null, "Enter radius value", "Circle Area", JOptionPane.QUESTION_MESSAGE);
double radius = Double.parseDouble(radiusString);
if (radius < 0){
System.out.println("Incorrect Input");
}
else {
Area = 3.14 * radius * radius;
System.out.println("The area of the circle is " + Area);
}
}
if (ShapeString.equals("S")){
String sideString = JOptionPane.showInputDialog(null, "Enter side value", "Square Area", JOptionPane.QUESTION_MESSAGE);
double side = Double.parseDouble(sideString);
if (side < 0){
System.out.println("Incorrect Input");
}
else {
Area = side * side;
System.out.println("The area of the square is " + Area);
}
}
if (ShapeString.equals("R")){
String heightString = JOptionPane.showInputDialog(null, "Enter height value", "Rectangle Area", JOptionPane.QUESTION_MESSAGE);
String widthString = JOptionPane.showInputDialog(null, "Enter width value", "Rectangle Area", JOptionPane.QUESTION_MESSAGE);
double height = Double.parseDouble(heightString);
double width = Double.parseDouble(widthString);
if (height < 0){
System.out.println("Incorrect Input");
}
else {
Area = height * width;
System.out.println("The area of the Rectangle is " + Area);
}
}
}
}

Code Java:

However, I do not know how to return the final

I have a array of numbers like

1, 3, 2, 1, 2 - These number determine how many pairs should be stored in a structure.

Then I have an array of numbers like

1,2 2,1 3,1 2,1 4,2 1,2.....These are the pairs of numbers that the first array points to so..

the first structure should have 1 pair and be 1,2, the second would have 3 pairs and be 2,1 3,1 2,1... and so on but I'm having issues getting this result.

This is what I currently do with vcountData being the first array holding the number of pairs for each infuence structure and vData being the actual pairs of data. This isn't bit right when it's getting the pairs together.

Code :

int numIndexPairs = 0;
for(int i = 0; i < vData.length; i+=(Integer.parseInt(vcountData[numIndexPairs])*2))
{
Infuence infuence = new Infuence();
for(int m = 0; m < Integer.parseInt(vcountData[numIndexPairs]); m++)
{
infuence.jointNames.add(Integer.toString(m));
infuence.jointIndices.add(vData[i+(m*2)]);
infuence.weights.add(vData[(i+(m*2)+1)]);
}
infuenceList.add(infuence);
numIndexPairs++;
if(numIndexPairs >= vcountData.length)
break;
}