مشق کی تعداد مشکل کی سطح کی نشاندہی کرتی ہے، آسان سے پیچیدہ تک۔ اگر آپ کے کوئی تبصرے، سوالات یا مشورے ہیں: ہمیں 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 لوپ جیسے لوپ کا استعمال کریں گے۔
تکراری حل بنانے کے لیے، ہمیں ایک بیس کیس کی ضرورت ہے جہاں پروگرام ختم ہو جائے اور تکرار رک جائے۔ ہم دیکھتے ہیں کہ بیس کیس 1 کا فیکٹوریل ہے، جو کہ 1 ہے، لہذا جب آپ کا فنکشن فیکٹوریل (1) کو کال کرتا ہے تو آپ بغیر کسی حساب کے صرف 1 واپس کر سکتے ہیں۔ اور، اگر نمبر 1 سے زیادہ ہے، تو ہم اسی فیکٹریل کو n - 1 کے ساتھ کال کر کے بار بار فیکٹوریل فارمولے کو لاگو کرتے رہتے ہیں۔ ایک بار جب ان پٹ 1 ہو جاتا ہے، تو طریقہ ریکسریو کال کو ختم کر دیتا ہے اور 1 کو واپس کر دیتا ہے۔ وہاں سے طریقہ اسٹیک ہوتا ہے۔ نیچے سکرول کرنا شروع کیا اور آخر میں ایک عدد کا فیکٹوریل شمار کیا جاتا ہے اور واپس کیا جاتا ہے۔
اس کے بجائے تکرار کا استعمال کرتے ہوئے، اور پھر فیکٹریل n کی گنتی کرنے کے لیے for لوپ! = این(این -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();
}
}
جاوا میں سٹرنگ کو ریورس کرنے کے بہت سے طریقے ہیں۔ ہم کسی بھی String آبجیکٹ کے مواد کو تیزی سے ریورس کرنے کے لیے جدید Java API استعمال کر سکتے ہیں۔ جاوا لائبریری ریورس () طریقہ کے ساتھ StringBuffer اور StringBuilder کلاسز فراہم کرتی ہے جسے جاوا میں String کو ریورس کرنے کے لیے استعمال کیا جا سکتا ہے۔ لیکن چونکہ ریورس recursive ہے، ہم recursion استعمال کر سکتے ہیں۔
StringBuffer یا دیگر API طریقوں کا استعمال کیے بغیر جاوا میں کسی مخصوص سٹرنگ کو ریورس کرنے کے لیے الگورتھم اور کوڈز یہ ہیں۔ ذیل کا طریقہ بتاتا ہے کہ سٹرنگ کو کیسے ریورس کیا جائے، جسے آپ مزید یہ چیک کرنے کے لیے دوبارہ استعمال کر سکتے ہیں کہ آیا دی گئی سٹرنگ پیلینڈروم ہے یا نہیں۔
ابتدائی ان پٹ کی توثیق کرنے کے بعد، سٹرنگ کو حرف بہ حرف دیکھا جاتا ہے، آخر سے شروع تک اور ایک الٹا سٹرنگ تیار کرتا ہے۔
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();
}
}
انڈیکس کو منظم کرنے کے لیے، آئیے انڈیکس کلاس بنانے کے ساتھ آگے بڑھیں جہاں طریقے پڑھے جائیں انڈیکس، انڈیکس داخل کریں اور انڈیکس کو ہٹا دیں۔ آپریشنز ہمیشہ بائنری کلید کی تلاش سے پہلے ہوتے ہیں۔
ڈیٹا سٹرکچر میں لچک پیدا کرنے کے لیے بہتر ہے کہ ایک arraylist استعمال کی جائے۔
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;
}
}
انڈیکس کو منظم کرنے کے لیے، آئیے انڈیکس کلاس بنانے کے ساتھ آگے بڑھیں جہاں طریقے پڑھے جائیں انڈیکس، انڈیکس داخل کریں اور انڈیکس کو ہٹا دیں۔ آپریشنز ہمیشہ بائنری کلید کی تلاش سے پہلے ہوتے ہیں۔
ڈیٹا سٹرکچر میں لچک پیدا کرنے کے لیے بہتر ہے کہ ایک arraylist استعمال کی جائے۔
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
Veeam کی طرف سے Coveware سائبر بھتہ خوری کے واقعات کے ردعمل کی خدمات فراہم کرتا رہے گا۔ Coveware فرانزک اور تدارک کی صلاحیتیں پیش کرے گا…
پیشن گوئی کی دیکھ بھال تیل اور گیس کے شعبے میں انقلاب برپا کر رہی ہے، پلانٹ کے انتظام کے لیے ایک جدید اور فعال نقطہ نظر کے ساتھ۔
UK CMA نے مصنوعی ذہانت کے بازار میں بگ ٹیک کے رویے کے بارے میں ایک انتباہ جاری کیا ہے۔ وہاں…
عمارتوں کی توانائی کی کارکردگی کو بڑھانے کے لیے یورپی یونین کی طرف سے تیار کردہ "گرین ہاؤسز" فرمان نے اپنے قانون سازی کے عمل کو اس کے ساتھ ختم کیا ہے…