ව්යායාමයේ අංකනය සරලම සිට වඩාත් සංකීර්ණ දක්වා දුෂ්කරතා මට්ටම පෙන්නුම් කරයි. ඔබට කිසියම් අදහස්, ප්රශ්න හෝ යෝජනා තිබේ නම්: info @ හි අපට ලියන්නbloginnovazione.it
import java.util.Scanner;
public class CompareTwoStrings {
public static void main(String[] args) {
Scanner risposta = new Scanner(System.in);
System.out.println("Inserisci la prima stringa");
String str1 = risposta.nextLine();
System.out.println("Inserisci la seconda stringa");
String str2 =risposta.nextLine();
if(str1.equals(str2))
{
System.out.println("La stringa " + str1 + " è uguale a " + str2);
}
else
{
System.out.println("La stringa " + str1 + " è diversa da " + str2);
}
risposta.close();
}
}
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CompareTwoStrings {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Digitare prima stringa:");
String str1 = input.nextLine();
System.out.println("Digitare seconda stringa:");
String str2 = input.nextLine();
boolean verifica = str1.equals(str2); // check equals
boolean verificaContenuto1 = str1.contains(str2); //check inclusion
boolean verificaContenuto2 = str2.contains(str1);
if (verifica){
System.out.println("La stringa " + str1 + " è uguale alla stringa "+ str2 + " (sensibile al maiuscolo).");
}
else if (verificaContenuto1){
Pattern p = Pattern.compile(str2);
Matcher m = p.matcher(str1);
int count1 = 0;
while(m.find()){
count1 += 1;
}
System.out.println("La stringa2 " + str2 + " è contenuta nella stringa1 " + str1 + " " + count1 + " volte.");
}
else if (verificaContenuto2){
Pattern p = Pattern.compile(str1);
Matcher m = p.matcher(str2);
int count2 = 0;
while(m.find()){
count2 += 1;
}
System.out.println("La stringa1 " + str1 + " è contenuta nella stringa2 " + str2 + " " + count2 + " volte.");
}
else {
System.out.println("La stringa " + str1 + " è diversa alla stringa " + str2 + ".");
}
input.close();
System.out.println("Fine.");
}
}
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CompareTwoStrings {
public static String bi2int (String bin){
char[] numbers = binary.toCharArray();
int result = 0;
for(int i=numbers.length - 1; i>=0; i--)
if(numbers[i]=='1'){
result += Math.pow(2, (numbers.length-i - 1));
}
return result;
}
public static String bi2esa (String bin){
}
public static String int2bi (String integer){
int integer1 = Integer.parseInt(integer);
String result = Integer.toBinaryString(integer1);
return result;
}
public static String int2esa (String integer){
}
public static String esa2bi (String esa){
}
public static String esa2int (String esa){
}
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Digitare un numero binario, intero o esadecimale:");
String numero = input.nextLine();
Pattern pBinario = Pattern.compile("[A-Z]"|"[2-9]", Pattern.CASE_INSENSITIVE);
Matcher mBinario = pBinario.matcher(numero);
boolean binario = mBinario.find();
Pattern pIntero = Pattern.compile("[A-Z]", Pattern.CASE_INSENSITIVE);
Matcher mIntero = pIntero.matcher(numero);
boolean intero = mIntero.find();
Pattern pEsadecimale = Pattern.compile("[G-Z]", Pattern.CASE_INSENSITIVE);
Matcher mEsadecimale = pEsadecimale.matcher(numero);
boolean esadecimale = mEsadecimale.find();
if (binario){
System.out.println(numero + " è binario!");
System.out.println("In interi corrisponde a " + bi2int(numero) + ",");
System.out.println("in esadecimali corrisponde a " + bi2esa(numero) + ".");
}
if (intero){
System.out.println(numero + " è intero!");
System.out.println("In binario corrisponde a " + int2bi(numero) + ",");
System.out.println("in esadecimali corrisponde a " + int2esa(numero) + ".");
}
if (esadecimale){
System.out.println(numero + " è esadecimale!");
System.out.println("In binario corrisponde a " + esa2bi(numero) + ",");
System.out.println("in interi corrisponde a " + esa2int(numero) + ".");
}
if (!esadecimale && !intero && !binario){
System.out.println("Input errato!");
}
input.close();
}
}
මෙම වැඩසටහන සෙල්සියස් අංශක උෂ්ණත්වයට අනුරූප පෙළ ක්ෂේත්රයේ ඇතුළත් කළ අගය කියවයි. ඇතුළත් කළ පාඨය හිස් නම්, කිසිදු මෙහෙයුමක් සිදු නොකළ යුතුය; එසේ නොමැතිනම් පෙළ ද්විත්ව අගයකට පරිවර්තනය කර කෙල්වින් අංශක ලබා ගැනීම සඳහා මෙම අගය 273.15 කින් වැඩි කරනු ලැබේ, පසුව ඒවා අදාළ පෙළ ක්ෂේත්රයට ලියා ඇත.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class ConvertitoreTemperatura extends JFrame implements ActionListener{
JButton btnConverti;
JLabel lbTempCelsius, lbTempKelvin;
JTextField txtTempCelsius, txtTempKelvin;
JPanel pannello, pann1, pann2;
public ConvertitoreTemperatura() {
pannello = new JPanel();
pann1 = new JPanel(new GridLayout(0,1));
pann2 = new JPanel();
txtTempCelsius = new JTextField("",10);
txtTempKelvin = new JTextField("",10);
lbTempCelsius = new JLabel("Temperatura in Celsius");
lbTempKelvin = new JLabel("Temperatura in Kelvin");
btnConverti = new JButton("Converti Temperatura");
pann1.add(lbTempCelsius);
pann1.add(txtTempCelsius);
pann1.add(lbTempKelvin);
pann1.add(txtTempKelvin);
pann2.add(btnConverti);
pannello.add(pann1);
pannello.add(pann2);
setContentPane(pannello);
btnConverti.addActionListener(this);
setTitle("Convertitore Temperatura ");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setSize(400,150);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String str = txtTempCelsius.getText();
if (!str.contentEquals("")) {
double d = Double.parseDouble(str);
d = d + 273.15;
txtTempKelvin.setText(""+d);
}
}
public static void main(String[] args) {
ConvertitoreTemperatura frame = new ConvertitoreTemperatura();
}
}
public class SommaConcatenazione {
public static void main(String[] args) {
char simbolo;
int numero1;
int numero2;
String parola1;
String parola2;
int risultato;
String risultatoStringa;
Scanner scanner = new Scanner(System.in);
System.out.println("scegli l'operazione: numeri (n), Stringhe (s)");
simbolo = scanner.nextLine().charAt(0);
switch (simbolo) {
case 'n':
System.out.println("inserisci un numero");
numero1 = scanner.nextInt();
System.out.println("inserisci il secondo numero");
numero2 = scanner.nextInt();
risultato = numero1 + numero2;
System.out.println(numero1 + " + " + numero2 + " = " + risultato);
break;
case 's':
System.out.println("inserisci una parola");
parola1 = scanner.nextLine();
System.out.println("inserisci la seconda parola");
parola2 = scanner.nextLine();
risultatoStringa = parola1 + parola2;
System.out.println(parola1 + " " + parola2 + " = " + risultatoStringa);
break;
default:
System.out.println("operazione non valido");
break;
}
scanner.close();
System.out.println("FINE");
}
}
import java.util.Scanner;
public class Main{
public static int somma (int addendo1, int addendo2)
{
return addendo1 + addendo2;
};
public static String somma(String addendo1, String addendo2)
{
return addendo1 + addendo2;
};
public static void main(String[] args){
Scanner risposta = new Scanner(System.in);
System.out.println("Cosa vuoi sommare? 1-numeri....2-stringhe");
int input = risposta.nextInt();
if( input == 1)
{
System.out.println("Inserisci il primo numero");
int num1=risposta.nextInt();
System.out.println("Inserisci il secondo numero");
int num2=risposta.nextInt();
System.out.println("Il risultato è: "+ somma(num1,num2));
}
else
{
risposta.nextLine();
System.out.println("Inserisci la prima stringa");
String str1 = risposta.nextLine();
System.out.println("Inserisci la seconda stringa");
String str2 =risposta.nextLine();
System.out.println("Il risultato è: "+ somma(str1,str2));
}
risposta.close();
}
}
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Esercizio3 {
public static int somma(int addendo1, int addendo2){
return addendo1 + addendo2;
}
public static String somma(String stringa1, String stringa2){
return stringa1 + stringa2;
}
public static void main(String[] args) {
Scanner risposta = new Scanner(System.in);
System.out.println("Inserisci il primo valore");
String str1 = risposta.nextLine();
System.out.println("Inserisci il secondo valore");
String str2 =risposta.nextLine();
Pattern pattern1 = Pattern.compile("[A-Z]", Pattern.CASE_INSENSITIVE);
Matcher matcher1 = pattern1.matcher(str1.toUpperCase());
boolean matchFound1 = matcher1.find();
Pattern pattern2 = Pattern.compile("[A-Z]", Pattern.CASE_INSENSITIVE);
Matcher matcher2 = pattern2.matcher(str2.toUpperCase());
boolean matchFound2 = matcher2.find();
if( matchFound1 || matchFound2)
{
System.out.println("Il risultato è: "+ somma(str1,str2));
}
else
{
int num1 = Integer.parseInt(str1);
int num2 = Integer.parseInt(str2);
System.out.println("Il risultato è: "+ somma(num1,num2));
}
risposta.close();
}
}
පළමු අවස්ථාවේ දී අපි ප්රතිවර්තනය භාවිතා කරමු, එහිදී ක්රමයක් විසඳුම සඳහා කැඳවයි, දෙවන අවස්ථාවෙහිදී පුනරාවර්තනය ලබා ගැනීම සඳහා අපි for and while loop වැනි ලූපයක් භාවිතා කරමු.
පුනරාවර්තන විසඳුමක් නිර්මාණය කිරීම සඳහා, වැඩසටහන අවසන් වන සහ පුනරාවර්තනය නතර වන මූලික නඩුවක් අපට අවශ්ය වේ. අපි පාදක කේස් එක 1 ට සාධක වන බව දකිමු, එය 1 වේ, එබැවින් ඔබේ ශ්රිතය සාධක (1) ලෙස හඳුන්වන විට ඔබට කිසිදු ගණනය කිරීමක් නොකර 1 ආපසු ලබා දිය හැක. තවද, සංඛ්යාව 1 ට වඩා වැඩි නම්, අපි n - 1 සමඟ එකම සාධක ලෙස ඇමතීමෙන් අපි සාධක සූත්රය පුනරාවර්තන ලෙස යොදන්නෙමු. ආදානය 1 බවට පත් වූ පසු, ක්රමය ප්රත්යාවර්තී ඇමතුම අවලංගු කර 1 ආපසු ලබා දෙයි. එතැන් සිට ක්රම තොගය ඇත පහළට අනුචලනය කිරීමට පටන් ගත් අතර අවසානයේ අංකයක සාධක අගය ගණනය කර ආපසු ලබා දෙනු ලැබේ.
ඒ වෙනුවට පුනරාවර්තනය භාවිතා කිරීම, පසුව සාධක n ගණනය කිරීම සඳහා for loop භාවිතා කිරීම! = එන්(n-1)(n-2) ... ..1. අපි සංඛ්යාවෙන් ආරම්භ කර එය 1 න් ආරම්භ කරන ලද සාධක වලින් ගුණ කරන බව ඔබට පෙනෙනු ඇත, ඉන්පසු අංක 1 බවට පත් වන තෙක් අපි සංඛ්යාව එකකින් අඩු කරමු, එය අන් කිසිවක් නොවේ.(n-1)(n-2) ... ..1.
import java.util.Scanner;
public class Factorial{
public static int recursiveFactorial(int n)
{
if( n <= 1)
{
return 1;
}
else
{
return n * recursiveFactorial( n - 1 );
}
}
public static int iterativeFactorial(int n){
int result = 1;
for (int i = 1; i <= n; i++) {
result = result * i;
}
return result;
}
public static void main(String[] args){
Scanner input = new Scanner(System.in); // input
System.out.println("Insert an integer number: ");
int numero = input.nextInt();
if ( numero < 0 ){
System.out.println("The number must be positive!");
System.exit(0);
}
System.out.println("Recursive Factorial is: " + recursiveFactorial(numero));
System.out.println("Iterative Factorial is: " + iterativeFactorial(numero));
input.close();
}
}
Java වල string එකක් Reverse කරන්න ගොඩක් ක්රම තියෙනවා. ඕනෑම String වස්තුවක අන්තර්ගතය ඉක්මනින් ආපසු හරවා යැවීමට අපට උසස් ජාවා API භාවිතා කළ හැක. Java පුස්තකාලය StringBuffer සහ StringBuilder පන්ති සඳහා Java හි String ආපසු හැරවීමට භාවිතා කළ හැකි ප්රතිලෝම () ක්රමය සපයයි. නමුත් reverse එක recursive නිසා අපිට recursion භාවිතා කරන්න පුළුවන්.
StringBuffer හෝ වෙනත් API ක්රම භාවිතා නොකර Java හි යම් තන්තුවක් ආපසු හැරවීමට ඇල්ගොරිතම සහ කේත මෙන්න. පහත ක්රමය මඟින් තන්තුව ආපසු හරවන ආකාරය පෙන්වයි, ලබා දී ඇති තන්තුව palindrome ද නැද්ද යන්න පරීක්ෂා කිරීමට ඔබට එය නැවත භාවිත කළ හැක.
ආරම්භක ආදානය වලංගු කිරීමෙන් පසු, තන්තුව අක්ෂරයෙන් අනුලකුණට පැමිණ, අවසානයේ සිට ආරම්භය දක්වා ප්රතිලෝම තන්තුවක් ජනනය කරයි.
import java.util.Scanner;
public class ReverseString {
public static String reverseString(String str){
if( str.length() == 0 ){
return str;
}
else{
return str.charAt(str.length()-1) + reverseString( str.substring(0, str.length() - 1) );
}
}
public static void main(String[] args){
Scanner input = new Scanner(System.in); // input
System.out.println("Insert a phrase: ");
String stringa = input.nextLine();
System.out.println("String reversed is " + reverseString(stringa));
input.close();
}
}
දර්ශකය කළමනාකරණය කිරීම සඳහා, ක්රම කියවන සූචිය, දර්ශක ඇතුළු කිරීම සහ දර්ශකය ඉවත් කිරීම යන දර්ශක පන්තිය නිර්මාණය කිරීමට අපි ඉදිරියට යමු. මෙහෙයුම් සෑම විටම ද්විමය යතුරු සෙවීමකින් පෙරාතුව ඇත.
දත්ත ව්යුහයේ නම්යශීලී බවක් ඇති කර ගැනීම සඳහා අරා ලැයිස්තුවක් භාවිතා කිරීම වඩා හොඳය.
import java.util.Scanner;
import java.lang.Math;
import java.util.ArrayList;
//---------------------------------------------------------
// Main Class
//---------------------------------------------------------
public class Index {
//METODO MAIN
public static void main(String[] args){
Scanner input = new Scanner(System.in);
ArrayList<Integer> arrayInserito = new ArrayList<Integer>();
System.out.println("How many numbers do you want to enter ?");
int dimensione = input.nextInt();
int valoreLetto;
int i= 0;
for (i = 0; i <= (dimensione - 1); i++){
System.out.println("Input " + (i+1) + "^ Value");
valoreLetto = input.nextInt();
arrayInserito.add(valoreLetto);
}
VettoreNum primoArray = new VettoreNum(arrayInserito);
String decisione = "Y";
while (decisione.equalsIgnoreCase("Y")){
System.out.println("What execute ?");
System.out.println("(0) = INSERT Key");
System.out.println("(1) = REMOVE Key");
System.out.println("(2) = END");
int scelta = input.nextInt();
if (scelta == 2)
continue;
else {
System.out.println("Input key to search:");
int chiave = input.nextInt();
if (chiave < 0){
System.out.println("Error: the key must be positive.");
System.exit(0);
}
switch (scelta){
//Insert
case 0:
System.out.println("Array: " + primoArray.vettore);
System.out.println("The key is in the index : " + primoArray.cercaValore(chiave));
System.out.println("Position: " + primoArray.getPosizione());
System.out.println("The index after insert:");
System.out.println(primoArray.inserisciValore(chiave));
break;
//Remove
case 1:
System.out.println("Array: " + primoArray.vettore);
System.out.println("The key is in the index: " + primoArray.cercaValore(chiave));
if (primoArray.cercaValore(chiave)){
System.out.println("Position: " + primoArray.getPosizione());
System.out.println("The index after remove:");
System.out.println(primoArray.rimuoviValore(chiave));
}
else
System.out.println("The key is not in the index.");
break;
//no valid input
default:
System.out.println("Error: please insert a valid number.");
}
}
System.out.println("Do you want to do another ? (Y or N)");
decisione = input.next();
}
input.close();
System.out.println("END.");
}
}
//----------------------------------------------------------------
//CLASS VECTORNUM
//----------------------------------------------------------------
class VectorNum {
public int lunarray;
public int posizione;
public ArrayList<Integer> vettore;
public int sup;
public int inf;
public ArrayList<Integer> newArray;
public VettoreNum (ArrayList<Integer> vettore){
this.vettore = vettore;
this.lunarray = vettore.size();
this.posizione = -1;
this.inf = 0;
this.sup = vettore.size() - 1;
this.newArray = new ArrayList<Integer>();
}
public int getPosizione(){
return this.posizione;
}
public boolean cercaValore (int chiave){
if((this.sup - this.inf) > 1){
int m = Math.round((this.sup + this.inf)/2);
if (chiave < this.vettore.get(m)){
this.sup = m;
}
else {
this.inf = m;
}
cercaValore(chiave);
}
if (chiave <= this.vettore.get(this.inf))
this.posizione = this.inf;
else if (chiave <= this.vettore.get(this.sup))
this.posizione = this.sup;
else
this.posizione = this.sup + 1;
return (this.vettore.get(this.inf) == chiave || this.vettore.get(this.sup) == chiave);
}
public ArrayList<Integer> inserisciValore (int chiave){
newArray.clear();
int i;
for (i = 0; i < this.lunarray + 1; i++){
if (i < this.posizione)
this.newArray.add(this.vettore.get(i));
else if (i == this.posizione)
this.newArray.add(chiave);
else
this.newArray.add(this.vettore.get(i - 1));
}
this.vettore = this.newArray;
return this.vettore;
}
public ArrayList<Integer> rimuoviValore (int chiave){
vettore.remove(posizione);
return this.vettore;
}
}
දර්ශකය කළමනාකරණය කිරීම සඳහා, ක්රම කියවන සූචිය, දර්ශක ඇතුළු කිරීම සහ දර්ශකය ඉවත් කිරීම යන දර්ශක පන්තිය නිර්මාණය කිරීමට අපි ඉදිරියට යමු. මෙහෙයුම් සෑම විටම ද්විමය යතුරු සෙවීමකින් පෙරාතුව ඇත.
දත්ත ව්යුහයේ නම්යශීලී බවක් ඇති කර ගැනීම සඳහා අරා ලැයිස්තුවක් භාවිතා කිරීම වඩා හොඳය.
import java.io.File;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.FileNotFoundException;
public class Exercise_11 {
public static void main(String[] args) throws FileNotFoundException{
File mioFile = new File("textinput.txt");
if (!mioFile.exists()){//---------------------------------------------- file doesn't exist
System.out.println("File not found.");
}
else {//--------------------------------------------------------------- file exists
System.out.println("File exist.");
Scanner lettore = new Scanner(mioFile);
ArrayList<Integer> collezione = new ArrayList<Integer>();
while (lettore.hasNextLine()) {
int riga = lettore.nextInt();
collezione.add(riga);
}
lettore.close();
switch (collezione.size()){
case 0:
System.out.println("File empty.");
break;
case 1:
System.out.println(collezione.get(0));
break;
case 2:
System.out.println("Two numbers, and the sum is: " + (collezione.get(0)+collezione.get(1)));
break;
default:
System.out.println("More than two numbers, and the result is: " + prodotto(collezione));
}
}
}
public static int prodotto (ArrayList<Integer> x){
int i = 0;
int a = x.get(0);
for (i = 1; i<= (x.size()-1); i++){
a = a * x.get(i);
}
return a;
}
}
වගු කළමනාකරණය කිරීම සඳහා අපි කළමනාකරණය සඳහා ක්රම සහ ගුණාංග සහිත වගු පන්තියක් සාදා ඇත. මෙනුව කළමනාකරණය කළේ HashMap විසිනි
import java.util.Scanner;
import java.util.HashMap;
//--------------------------------------------------------------------
// MAIN CLASS
//--------------------------------------------------------------------
public class Restaurant {
// Main method
public static void main(String[] args){
Scanner input = new Scanner(System.in);
// Tables:
Table tavolo1 = new Table(1,1);
Table tavolo2 = new Table(2,2);
Table tavolo3 = new Table(3,2);
Table tavolo4 = new Table(4,8);
Table tavolo5 = new Table(5,8);
Table tavolo6 = new Table(6,8);
// Menu as HashMap:
HashMap<Integer, Integer> menu = new HashMap<Integer, Integer>();
menu.put(1,5);
menu.put(2,4);
menu.put(3,1);
menu.put(4,12);
menu.put(5,1);
menu.put(6,2);
// Handle of request at the tables:
while (true){
System.out.println("Next Customers ?");
System.out.println("(1): take a table");
System.out.println("(2): Get an order");
System.out.println("(3): The Bill");
System.out.println("(0): Go Out.");
int operazione = input.nextInt();
if (operazione == 0)
break;
//switch on previous request:
switch (operazione){
// Take a table------------------------------------------
case 1:
System.out.println("Hoe many seats ?");
System.out.println("(1): One seat");
System.out.println("(2): Two seats");
System.out.println("(3): from two to eight seats");
int persone = input.nextInt();
// switch on number of seats
switch (persone){
// One seat
case 1:
if (tavolo1.libero){
tavolo1.setOccupato();
System.out.println("Table number One !");
}
else
System.out.println("Sold Out.");
break;
// Two seats
case 2:
if (tavolo2.libero){
tavolo2.setOccupato();
System.out.println("Table number Two !");
}
else if (tavolo3.libero){
tavolo3.setOccupato();
System.out.println("Table number Three !");
}
else
System.out.println("Sodl out.");
break;
// 3 to 8 seats
case 3:
if (tavolo4.libero){
tavolo4.setOccupato();
System.out.println("Table number Four !");
}
else if (tavolo5.libero){
tavolo5.setOccupato();
System.out.println("Table number Five !");
}
else if (tavolo6.libero){
tavolo6.setOccupato();
System.out.println("Table number Six !");
}
else
System.out.println("Sold Out.");
break;
// more than eight seats
default:
System.out.println("Not available.");
}
break;
// Show Menu and take an order------------------------
case 2:
System.out.println("Tanle number:");
int num = input.nextInt();//table number to get order
System.out.println(".");
//switch on table to order:
switch (num){
case 1:
//loop to show menu on order
while (true){
System.out.println("MENU:");
System.out.println("(1) rise $5");
System.out.println("(2) spaghetti $4");
System.out.println("(3) chicken $10");
System.out.println("(4) salmon $12");
System.out.println("(5) Water $1");
System.out.println("(6) coca cola $2");
System.out.println(".");
System.out.println("Insert order (0) to exit:");
int selezione = input.nextInt();
if (selezione == 0)
continue;
else {
tavolo1.setOrdineAttuale(selezione, menu.get(selezione));
}
System.out.println("It's enough ?");
System.out.println("(1): Y; (2): N");
int ancora = input.nextInt();
if (ancora == 2)
break;
}
break;
case 2:
while (true){
System.out.println("MENU:");
System.out.println("(1) rise $5");
System.out.println("(2) spaghetti $4");
System.out.println("(3) chicken $10");
System.out.println("(4) salmon $12");
System.out.println("(5) Water $1");
System.out.println("(6) coca cola $2");
System.out.println(".");
System.out.println("Insert order (0) to exit:");
int selezione = input.nextInt();
if (selezione == 0)
continue;
else {
tavolo2.setOrdineAttuale(selezione, menu.get(selezione));
}
System.out.println("It's enough ?");
System.out.println("(1): Y; (2): N");
int ancora = input.nextInt();
if (ancora == 2)
break;
}
break;
case 3:
while (true){
System.out.println("MENU:");
System.out.println("(1) rise $5");
System.out.println("(2) spaghetti $4");
System.out.println("(3) chicken $10");
System.out.println("(4) salmon $12");
System.out.println("(5) Water $1");
System.out.println("(6) coca cola $2");
System.out.println(".");
System.out.println("Insert order (0) to exit:");
int selezione = input.nextInt();
if (selezione == 0)
continue;
else {
tavolo3.setOrdineAttuale(selezione, menu.get(selezione));
}
System.out.println("It's enough ?");
System.out.println("(1): Y; (2): N");
int ancora = input.nextInt();
if (ancora == 2)
break;
}
break;
case 4:
while (true){
System.out.println("MENU:");
System.out.println("(1) rise $5");
System.out.println("(2) spaghetti $4");
System.out.println("(3) chicken $10");
System.out.println("(4) salmon $12");
System.out.println("(5) Water $1");
System.out.println("(6) coca cola $2");
System.out.println(".");
System.out.println("Insert order (0) to exit:");
int selezione = input.nextInt();
if (selezione == 0)
continue;
else {
tavolo4.setOrdineAttuale(selezione, menu.get(selezione));
}
System.out.println("It's enough ?");
System.out.println("(1): Y; (2): N");
int ancora = input.nextInt();
if (ancora == 2)
break;
}
break;
case 5:
while (true){
System.out.println("MENU:");
System.out.println("(1) rise $5");
System.out.println("(2) spaghetti $4");
System.out.println("(3) chicken $10");
System.out.println("(4) salmon $12");
System.out.println("(5) Water $1");
System.out.println("(6) coca cola $2");
System.out.println(".");
System.out.println("Insert order (0) to exit:");
int selezione = input.nextInt();
if (selezione == 0)
continue;
else {
tavolo5.setOrdineAttuale(selezione, menu.get(selezione));
}
System.out.println("It's enough ?");
System.out.println("(1): Y; (2): N");
int ancora = input.nextInt();
if (ancora == 2)
break;
}
break;
case 6:
while (true){
System.out.println("MENU:");
System.out.println("(1) rise $5");
System.out.println("(2) spaghetti $4");
System.out.println("(3) chicken $10");
System.out.println("(4) salmon $12");
System.out.println("(5) Water $1");
System.out.println("(6) coca cola $2");
System.out.println(".");
System.out.println("Insert order (0) to exit:");
int selezione = input.nextInt();
if (selezione == 0)
continue;
else {
tavolo6.setOrdineAttuale(selezione, menu.get(selezione));
}
System.out.println("It's enough ?");
System.out.println("(1): Y; (2): N");
int ancora = input.nextInt();
if (ancora == 2)
break;
}
break;
default:
System.out.println("Invalid table");
}
break;
// Payment and table available---------------------------
case 3:
System.out.println("Insert number of table:");
int numero = input.nextInt();
System.out.println(".");
//switch on table ID
switch (numero){
case 1:
int conto1 = somma(tavolo1.ordineAttuale);
System.out.println("Amount to pay: $" + conto1);
tavolo1.ordineAttuale = null;
tavolo1.libero = true;
break;
case 2:
int conto2 = somma(tavolo2.ordineAttuale);
System.out.println("Amount to pay: $" + conto2);
tavolo2.ordineAttuale = null;
tavolo2.libero = true;
break;
case 3:
int conto3 = somma(tavolo3.ordineAttuale);
System.out.println("Amount to pay: $" + conto3);
tavolo3.ordineAttuale = null;
tavolo3.libero = true;
break;
case 4:
int conto4 = somma(tavolo4.ordineAttuale);
System.out.println("Amount to pay: $" + conto4);
tavolo4.ordineAttuale = null;
tavolo4.libero = true;
break;
case 5:
int conto5 = somma(tavolo5.ordineAttuale);
System.out.println("Amount to pay: $" + conto5);
tavolo5.ordineAttuale = null;
tavolo5.libero = true;
break;
case 6:
int conto6 = somma(tavolo6.ordineAttuale);
System.out.println("Amount to pay: $" + conto6);
tavolo6.ordineAttuale = null;
tavolo6.libero = true;
break;
default:
System.out.println("Table not available.");
}
break;
default:
System.out.println("Sold out.");
}
}
input.close();
}
// Method to sum amount of order
public static int somma(HashMap<Integer, Integer> conto){
int a = 0;
for (int i : conto.values()){
a = a + i;
}
return a;
}
}
//-----------------------------------------------------------------------
// Table class
//-----------------------------------------------------------------------
class Table {
public boolean libero;
public int tavoloID;
public int coperti;
HashMap<Integer, Integer> ordineAttuale;
public Table (int numero, int posti){
this.libero = true;
this.tavoloID = numero;
this.coperti = posti;
this.ordineAttuale = new HashMap<Integer, Integer>();
}
// table not available
public void setOccupato(){
libero = false;
}
// available table
public void setLibero(){
libero = true;
}
// check the state of the table:
public boolean getStato(){
return this.libero;
}
//
public void setOrdineAttuale(int uno, int due){
ordineAttuale.put(uno, due);
}
}
කෙටුම්පත් කිරීම BlogInnovazione.it
වර්ණ ගැන්වීම හරහා සියුම් මෝටර් කුසලතා වර්ධනය කිරීම ලිවීම වැනි වඩාත් සංකීර්ණ කුසලතා සඳහා දරුවන් සූදානම් කරයි. වර්ණ ගැන්වීමට...
නාවික අංශය සැබෑ ගෝලීය ආර්ථික බලවතෙකු වන අතර එය බිලියන 150 ක වෙළඳපලක් කරා ගමන් කර ඇත.
පසුගිය සඳුදා ෆිනෑන්ෂල් ටයිම්ස් OpenAI සමඟ ගිවිසුමක් නිවේදනය කළේය. FT එහි ලෝක මට්ටමේ පුවත්පත් කලාවට බලපත්ර ලබා දෙයි…
මිලියන ගණනක් ජනතාව ප්රවාහ සේවා සඳහා ගෙවයි, මාසික දායක ගාස්තු ගෙවයි. පොදු මතය වන්නේ ඔබ...