Wednesday, March 26, 2014

RainfallApp v2

This is the RainFallApp v2. It take takes the input name of the two months, then finds the rainfall amount for that month and then outputs the average between the two months.


import java.util.Scanner;

public class RainFallApp {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.print("Please enter the first month: ");
        String aMonth = input.nextLine();

        System.out.print("Please enter the second month: ");
        String bMonth = input.nextLine();


        rainfall aRainfall = new rainfall();
        String aName = aRainfall.rainAmount(aMonth);
        Double aAmount = Double.parseDouble(aName);

        rainfall bRainfall = new rainfall();
        String bName = bRainfall.rainAmount(bMonth);
        Double bAmount = Double.parseDouble(bName);

        double Avg = (aAmount + bAmount) / 2;

        System.out.println("\nIn the month of " + aMonth + " it had " + aAmount + " inches of rain.");
        System.out.println("In the month of " + bMonth + " it had " + bAmount + " inches of rain.");
        System.out.println("The average rainfall between the two months is: " + Avg);

    }

}

class rainfall {
    private String Rain_Amount;

    String rainAmount(String rainMonth) {
        Rain_Amount = getAmount(rainMonth);
        return Rain_Amount;
    }

    private String getAmount(String rainMonth) {

        if (rainMonth.equals("Jan")) {
            Rain_Amount = "3.3";

        }
        else if (rainMonth.equals("Feb")) {
            Rain_Amount = "2.3";
        }
        else {
            System.out.println("Not a valid month name");
        }
        return Rain_Amount;
    }
}


Friday, March 7, 2014

timeApp

**POSTPONED SINCE I NEED MORE INFO**


CMPS 1044 Program 3 Spring 2014 –  Long-Distance Calls


Problem solving steps & Manually Calculated Answers

Problem Description
A long-distance carrier charges the following rates for telephone calls between the U.S. and Mexico:

Starting time of Call (hour:minutes)
Rate Per Minute
00:00 06:59 (midnight 6:59 a.m.)
$ 0.12
07:00 19:00 (7 a.m. – 7 p.m.)
0.55
19:01 23:59 (after 7 p.m. before midnight)
0.35

Given the StartTime of a call and the Length of the call in minutes, the cost for the call is to be calculated.  The time is input as a decimal number. That is, 5:45 will be input as 5.45.  You MUST split this into the integer Hour and Minute components then validate the correct format of each one. When printing, you must print the time as 05:45, with the colon not the period.  Use a while loop counting to 17, like you did in the first 2 programs. ** Use if statements, properly nested, to solve the problem.  All I/O is to be file based.

Data File ( Name, StartTime, Length (in minutes))
Mary
5.45
10
Joe
16.41
40
Ted
23.10
38
Joshua
45.9
2
Fred
12.42
50
Caroline
23.00
121
Jeffrey
19.00
82
Joy
24.00
13
Paul
06.59
8
Tony
7.00
29
Henry
19.01
59
Catherine
23.08
134
Titus
10.60
65
Julio
5.37
100
Rebekah
12.03
81
Andy
23.59
5
TalkMonkey
22.00
300

Input Validation:  You must check Hour & Minute after reading it in.  That is, if Hour is greater than 23 or if Minute is greater than 59, then you will print the word ERROR in the CHARGE column. Otherwise, you calculate and print the total cost.

Output Form:  Make sure that your output looks as below.
Your Name

Long Distance Telephone Bills
Name   Start Time Length    Charge
-------------------------------------------------------- David     12:42    100      $ 55.00   NOTE: Alignment
Julie     06:05     10      $  1.20   NOTE: Must manually print 0
Max       25:50     12        ERROR        for single digit times.
Cindy     12:89    100        ERROR


Thursday, March 6, 2014

expApp

Programming Fundamentals
CS1336

Assignment #4 – Calculations and Selection Logic

Introduction
Your second programming assignment will consist of two small C++ programs. Each program will be independent of the other program. Each one should compile correctly and produce the specified output.
Please note that each of the programs should comply with the commenting and formatting rules we discussed in class. For example, there should be a header for the whole program that gives the author’s name, class name, date, and description. End braces should be commented, and there are alignment and indenting requirements as discussed. Please ask if you have any questions.

Program #1
For a more complex calculation program, please implement Problem 17 on page 146 of our text.
You may use the pow() function in the cmath header. This function has the following prototype:
double pow (double base, double power);
The “base” is the number that is being taken to some power, and the “power” is the power to which the base is taken. The function will return a double as the result.

Here is a scan from the book to help some of you who may not have the text.

package expApp;
import java.text.*;
import java.util.Scanner;

public class expApp {

 public static void main(String[] args) {
    
  Scanner input = new Scanner(System.in);
  DecimalFormat df = new DecimalFormat("0.00");

  double L;
  double interest;
  int N;
  
  System.out.print("Please enter your loan amount: ");
  L = input.nextDouble();
  
  System.out.print("Please enter your interest rate for the loan: ");
  interest = input.nextDouble();
  
  System.out.print("Lastly how many payments will you be making: ");
  N = input.nextInt();
  
  double Rate = ((interest / 12));
  double dRate = Rate / 100;
  double Payments = ((dRate * Math.pow((1+dRate), N)) / ((Math.pow((1+dRate), N)) -1)) *L;
  double totalPaid = (Payments * N);
  double interestPaid = totalPaid - L;
  
  System.out.println("\nLoan Amount:           $  " + df.format(L));
  System.out.println("Monthly interest rate:    " + Math.round(Rate) +"%");
  System.out.println("Number of Payments:       " + N);
  System.out.println("Monthly Payments of:   $  " + df.format(Payments));
  System.out.println("Amount Paid Back:      $  " + df.format(totalPaid));
  System.out.println("Interest Paid:         $  " + df.format(interestPaid));
 }

}