FinishedForNow
This commit is contained in:
BIN
Basics/target/classes/com/example/Basics.class
Normal file
BIN
Basics/target/classes/com/example/Basics.class
Normal file
Binary file not shown.
Binary file not shown.
46
Basics_II/src/main/java/com/example/BasicII.java
Normal file
46
Basics_II/src/main/java/com/example/BasicII.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package com.example;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class BasicII {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello world!");
|
||||||
|
|
||||||
|
int [] ages;
|
||||||
|
ages = new int[10];
|
||||||
|
int [] numbers = {15, 36, 18, 24, 47, 59, 26};
|
||||||
|
ages[2] = 15;
|
||||||
|
ages[0] = 18;
|
||||||
|
System.out.println(numbers[3]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
You are making a program for a vending machine that provides drinks.
|
||||||
|
The menu of the drinks is stored in an array called menu:
|
||||||
|
String[] menu = {"Tea", "Espresso", "Americano", "Water", "Hot Chocolate"};
|
||||||
|
JAVA
|
||||||
|
Take the choice of the customer as an integer from input and output the corresponding menu item.
|
||||||
|
Also, check for errors: in case the input is out of the range of the array, output "Invalid".
|
||||||
|
*/
|
||||||
|
String[] menu = {"Tea", "Espresso", "Americano", "Water", "Hot Chocolate"};
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
System.out.print("Your chouse from the vending machine [0-4]: ");
|
||||||
|
int choice = sc.nextInt();
|
||||||
|
if (choice > 4 || choice < 0) {
|
||||||
|
System.out.println("Invalid");
|
||||||
|
}else{
|
||||||
|
System.out.println(menu[choice]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
The given code declares an array that holds the monthly revenues for a company for a year.
|
||||||
|
You need to calculate the average monthly revenue for the year.
|
||||||
|
For that, calculate the sum of the revenue for all the months and divide it by the number of items in the array.
|
||||||
|
*/
|
||||||
|
double[] revenue = {88750, 125430, 99700, 14500, 158000, 65000, 99000, 189000, 210000, 42000, 165800, 258900};
|
||||||
|
double sum = 0;
|
||||||
|
for (double d : revenue) {
|
||||||
|
sum += d;
|
||||||
|
}
|
||||||
|
System.out.println(sum/revenue.length);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
package com.example;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("Hello world!");
|
|
||||||
}
|
|
||||||
}
|
|
BIN
Basics_II/target/classes/com/example/BasicII.class
Normal file
BIN
Basics_II/target/classes/com/example/BasicII.class
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user