Open Andy179176 opened 2 years ago
//#1_первод USD в EURO
package com.company;
public class Main {
public static void main(String[] args) {
int usd = 100;
double kurs = 1.2;
double result = resultVEuro(usd,kurs);
print(usd,kurs,result);
}
public static double resultVEuro(int usd, double kurs){
double result=usd/kurs;
return result;
}
public static void print(int usd, double kurs, double result){
System.out.println("Для оплаты "+usd+ "$ необходимо "+resultVEuro(usd,kurs)+" евро.");
}
}
//DZ_#2_процент от числа
package com.company;
public class Main {
public static void main(String[] args) {
double num1=1234.123;
double num2=15.5;
double result=procent(num1,num2);
System.out.println("Аргументы: ("+num1+", "+num2+") -> Результат "+result);
}
public static double procent(double num1, double num2){
double result=num1*num2/100;
return result;
}
}
/ DZ#3_оплата+комиссия (пришлось репу почесать первые минуты после получения задания:)) Но в процессе вроде сложностей не возникло. Названия методов чуток поменял с первых двух заданий) /
package com.company;
public class Main {
public static void main(String[] args) {
double usd = 100;
double kurs = 1.2;
double euro = convertVEuro(usd,kurs);
double procent=2;
double comissia=procentOtEuro(euro,procent);
print(usd, kurs, euro, procent, comissia);
}
public static double convertVEuro(double usd, double kurs){
double result=usd/kurs;
return result;
}
public static double procentOtEuro(double euro, double procent){
double result=euro*procent/100;
return result;
}
public static void print(double usd, double kurs, double euro, double procent, double comissia){
System.out.println("Для оплаты "+usd+ "$ необходимо "+euro+" евро + комиссия "+comissia+" евро. Размер комиссии "+procent+ "%");
}
}
/ DZ#4_сложение 4 чисел с помощью методов сложения 2 чисел. Не уверен, что я понял верно задание. Я просто сложил два метода (методы сложения двух чисел). /
package com.company;
public class Main {
public static void main(String[] args) {
double num1 = 1;
double num2 = 2;
double num3 = 3;
double num4 = 4;
System.out.println(addAll(num1, num2, num3, num4));
}
public static double addNum1iNum2(double num1, double num2){
double result = num1+num2;
return result;
}
public static double addNum3iNum4(double num1, double num2){
double result = num1+num2;
return result;
}
public static double addAll(double num1, double num2, double num3, double num4){
double result = addNum1iNum2(num1, num2) + addNum3iNum4(num3, num4);
return result;
}
}
// 1)
public static void main(String[] args) {
double usd, eur, exRate;
usd=324;
exRate=0.88;
eur=usdToEur(usd, exRate);
printConversion(usd, eur, exRate);
// 2)
double taxRate=3.2;
double calculatedTax = tax(eur, taxRate);
printTaxes(eur,taxRate,calculatedTax);
// 3)
double taxedEur=taxResult(eur,calculatedTax);
printTotal(taxedEur);
}
public static double usdToEur (double toConvert, double exRate){
double converted=toConvert*exRate;
return converted;
}
public static void printConversion (double usd, double eur, double exRate){
System.out.println("Your conversion is: " + usd + "$ = " + eur + "€\n" + "exchange rate is: " + exRate );
}
public static double tax (double amount, double taxValue){
double taxToPay=amount / 100 * taxValue;
return taxToPay;
}
public static void printTaxes(double eur, double taxRate, double calculatedTax){
System.out.println("for conversion of " + eur + " your total taxes are: " + calculatedTax + "€\n" + "tax rate " + taxRate + "%");
}
public static double taxResult (double eur, double taxToPay){
double taxedEur=eur-taxToPay;
return taxedEur;
}
public static void printTotal(double taxedEur){
System.out.println("your total converted Euros are:" + taxedEur + "€");
}
}
//4)
int num1=3;
int num2=5;
int num3=2;
int num4=9;
double sum=add(add(num1, num2), add(num3, num4));
System.out.println(num1 + "+" + num2 + "+" + num3 + "+" + num4 + "=" + sum);
}
public static double add (double num1, double num2){
double result=num1+num2;
return result;
}
}
Задание 1 public class Main {
public static void main(String[] args) {
double usd =100;
double excurrencyrate = 1.2;
double exresult = transfer(usd, excurrencyrate);
String output = String.format("%.3f",exresult);
System.out.println("to transfer " +usd + " in USDollar you need to pay " +output + " Euro");
}
public static double transfer(double usd, double excurrencyrate){
double result=usd/excurrencyrate;
return result;
}
}
Задание 2 public class Main {
public static void main(String[] args) {
// write your code here
double usd =500;
double excurrencyrate = 9;
double exresult = percent(usd, excurrencyrate);
String output = String.format("%.1f",exresult);
System.out.println("the " +output+ " is " +excurrencyrate+ " percent from " +usd );
}
public static double percent(double usd, double excurrencyrate){
double result=(usd*excurrencyrate)/100;
return result;
}
}
Задача 3 public class Main {
public static void main(String[] args) {
double usd =600;
double excurrencyrate = 1.2;
double fee=3;
double yourfee;
double exresult = transfer(usd, excurrencyrate);
String output = String.format("%.2f",exresult);
yourfee = percent(exresult,fee);
String outputyourfee = String.format("%.1f",yourfee);
System.out.println("To transfer " +usd + " in USDollar you need to pay " +output + " Euro");
System.out.println("Please note: From " +output+ " Euro you'll have to pay " + outputyourfee+ " Euro exchange fee");
}
public static double transfer(double usd, double excurrencyrate){
double result=usd/excurrencyrate;
return result;
}
public static double percent(double exresult, double fee){
double result=(exresult*fee)/100;
return result;
}
}
Задача 4 public class Main {
public static void main(String[] args) {
int num1 =36; int num2 =32; int num3 =55; int num4 =86; int result = add(num1, num2, num3, num4); output(num1, num2, num3, num4, result);
}
public static int add(int num1, int num2, int num3, int num4){
int result= num1+num2+num3+num4;
return result;
}
public static void output(int num1, int num2, int num3, int num4, int result){
System.out.println(num1+ "+" +num2+ "+" +num3+ "+"+num4+ "=" +result);
}
}
1) Let’s given an amount in American dollars (USD) we need to pay. I think obviously it should be a variable. But we have only Euro (EUR). The dollar rate is given too and should be variable too. So, using methods implement the program which prints the amount in euro.
For example: You need to pay 100$. The exchange rate USD/EUR is 1.2. The output is: “for the payment 100$ you need 83.3333 Euro 2) Implement the method that takes two arguments. The second argument specifies what percentage of the first number the method should return. For example: Arguments: (100, 11) -> result is 11
3) Imagine, you should take some % for every exchange operation. Implement this method using the methods from task 1) and task 2) 4) Using the method add for two numbers which we wrote on class implement a method for adding 4 numbers.