Java Programming Examples: If Else Statement, User Input, Account Class, Car Class, Exercises of Programming Languages

Various java programming examples. The first example demonstrates the use of if else statements with user input. The second example illustrates an account class with getter and setter methods. The third example shows a car class with properties and methods. The fourth example presents another account class with a transaction class.

Typology: Exercises

2019/2020

Uploaded on 04/23/2020

Mikrokosmos86
Mikrokosmos86 🇹🇷

4.7

(3)

7 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
If Else Basit Örneği
int x = 67;
int y = 89;
int toplam = x + y ;
if ( toplam < 100){
System.out.println("Sonucunuz Yanlış");
}
else if (toplam > 100)
System.out.println("Sonucunuz Doğru");
KULLANICIDAN VERİ ALINARAK YAZILAN BİR IF ELSE ÖRNEĞİ
import java.util.Scanner ;
public class Butterfly {
public static void main (String []args ){
Scanner s = new Scanner (System.in);
System.out.println("İlk Sayıyı Giriniz : ");
int sayı1=s.nextInt();
System.out.println("İkinci Sayıyı Giriniz : ");
int sayı2=s.nextInt();
if (sayı1>sayı2)
System.out.println(sayı1+" , "+sayı2+" ' den büyüktür");
else
System.out.println(sayı1+" , "+sayı2+" 'den küçüktür");
Banking Account
Accounts Sınıfı;
public class Accounts {
private double accountA ;
private double accountB;
public double getAccountA() {
return accountA;
}
public void setAccountA(double accountA) {
this.accountA = accountA;
}
public double getAccountB() {
return accountB;
}
public void setAccountB(double accountB) {
this.accountB = accountB;
}
}
Main Class;
pf3

Partial preview of the text

Download Java Programming Examples: If Else Statement, User Input, Account Class, Car Class and more Exercises Programming Languages in PDF only on Docsity!

If Else Basit Örneği

int x = 67;

int y = 89;

int toplam = x + y ;

if ( toplam < 100){

System.out.println("Sonucunuz Yanlış");

else if (toplam > 100)

System.out.println("Sonucunuz Doğru");

KULLANICIDAN VERİ ALINARAK YAZILAN BİR IF ELSE ÖRNEĞİ

import java.util.Scanner ;

public class Butterfly {

public static void main ( String []args ){

Scanner s = new Scanner ( System. in );

System. out .println("İlk Sayıyı Giriniz : ");

int sayı1 =s.nextInt();

System. out .println("İkinci Sayıyı Giriniz : ");

int sayı2 =s.nextInt();

if (sayı1>sayı2)

System. out .println(sayı1+" , "+sayı2+" ' den büyüktür");

else

System. out .println(sayı1+" , "+sayı2+" 'den küçüktür");

Banking Account

Accounts Sınıfı;

public class Accounts { private double accountA ; private double accountB; public double getAccountA() { return accountA; } public void setAccountA( double accountA) { this .accountA = accountA; } public double getAccountB() { return accountB; } public void setAccountB( double accountB) { this .accountB = accountB; } }

Main Class;

public class MainClass { public static void main (String args[]){ Transaction Balance = new Transaction (); Transaction Deposit = new Transaction (); Accounts accountA = new Accounts (); Accounts accountB = new Accounts (); accountA.equals(Balance); accountB.equals(Deposit); System. out .println( "accountA = " + Balance.getBalance()); System. out .println("accountB = " + Deposit.getDeposit()); } }

Transaction sınıfı;

public class Transaction { private double Balance = 500; private double Deposit = 400; private double Amount = 300; Accounts accountA = new Accounts (); Accounts accountB = new Accounts (); public double getDeposit() { return Deposit + Amount ; } public void setDeposit( double deposit) { Deposit = deposit; } public double getAmount() { return Amount; } public void setAmount( double amount) { Amount = amount; } public double getBalance() { return Balance - Amount; } public void setBalance() { this .Balance = Balance ; } }

ARABA KODU ;

Car Classı

public class car { String Color; String Model; double Engine; int Doors;