FinishedForNow

This commit is contained in:
2024-09-12 20:53:59 +02:00
parent 0ff7d99ee5
commit 3612a30c47
6 changed files with 46 additions and 7 deletions

Binary file not shown.

View 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);
}
}

View File

@ -1,7 +0,0 @@
package com.example;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

Binary file not shown.