Şimdi Ara

Java ile Takvim

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
3
Cevap
0
Favori
379
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Kod

    Yığını:
    import java.util.Scanner; public class Calendar { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Hangi yılın takvimini istersiniz?: "); int istenilenyıl = input.nextInt(); String[] aylar = {"Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"}; String[] günler = {"Pt", "Sa", "Ça", "Pe", "Cu", "Ct", "Pz"}; int[] aydakigün = {31, istenilenyıl % 4 == 0 && istenilenyıl % 100 != 0 || istenilenyıl % 400 == 0 ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int[] başlangıç = new int[12]; başlangıç[0] = 1; for (int a = 1; a < istenilenyıl; a++) { if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0) başlangıç[0] += 2; else başlangıç[0] += 1; başlangıç[0] %= 7; if (başlangıç[0] == 0) başlangıç[0] = 7; } for (int a = 1; a < 12; a++) { başlangıç[a] = (başlangıç[a - 1] + aydakigün[a - 1]) % 7; if (başlangıç[a] == 0) başlangıç[a] = 7; } for (int a = 0; a < 4; a++) System.out.printf(" %s ", aylar[a]); System.out.println(); for (int a = 0; a < 4; a++) for (int b = 0; b < 7; b++) { if (b != 6) System.out.printf("%s ", günler[b]); else System.out.printf("%s ", günler[b]); } System.out.println(); for (int a = 0; a < 4; a++) { for (int b = 1; b < başlangıç[a]; b++) { System.out.printf(" "); } for (int b = 1; b <= 8 - başlangıç[a]; b++) { if (b == 8 - başlangıç[a]) System.out.printf("%d ", b); else System.out.printf("%d ", b); } başlangıç[a] = 9 - başlangıç[a]; } System.out.println(); for (int x = 0; x < 5; x++) { for (int a = 0; a < 4; a++) { for (int b = 1; b <= 7; başlangıç[a]++) { if (başlangıç[a] < 10) { if (b == 7) System.out.printf("%d ", başlangıç[a]); else System.out.printf("%d ", başlangıç[a]); } else { if (aydakigün[a] >= başlangıç[a]) { if (b == 7) System.out.printf("%d ", başlangıç[a]); else System.out.printf("%d ", başlangıç[a]); } else { if (b == 7) System.out.printf(" "); else System.out.printf(" "); } } b++; } } System.out.println(); } for (int a = 4; a < 8; a++) System.out.printf(" %s ", aylar[a]); System.out.println(); for (int a = 0; a < 4; a++) for (int b = 0; b < 7; b++) { if (b != 6) System.out.printf("%s ", günler[b]); else System.out.printf("%s ", günler[b]); } System.out.println(); for (int a = 4; a < 8; a++) { for (int b = 1; b < başlangıç[a]; b++) { System.out.printf(" "); } for (int b = 1; b <= 8 - başlangıç[a]; b++) { if (b == 8 - başlangıç[a]) System.out.printf("%d ", b); else System.out.printf("%d ", b); } başlangıç[a] = 9 - başlangıç[a]; } System.out.println(); for (int x = 0; x < 5; x++) { for (int a = 4; a < 8; a++) { for (int b = 1; b <= 7; başlangıç[a]++) { if (başlangıç[a] < 10) { if (b == 7) System.out.printf("%d ", başlangıç[a]); else System.out.printf("%d ", başlangıç[a]); } else { if (aydakigün[a] >= başlangıç[a]) { if (b == 7) System.out.printf("%d ", başlangıç[a]); else System.out.printf("%d ", başlangıç[a]); } else { if (b == 7) System.out.printf(" "); else System.out.printf(" "); } } b++; } } System.out.println(); } for (int a = 8; a < 12; a++) System.out.printf(" %s ", aylar[a]); System.out.println(); for (int a = 0; a < 4; a++) for (int b = 0; b < 7; b++) { if (b != 6) System.out.printf("%s ", günler[b]); else System.out.printf("%s ", günler[b]); } System.out.println(); for (int a = 8; a < 12; a++) { for (int b = 1; b < başlangıç[a]; b++) { System.out.printf(" "); } for (int b = 1; b <= 8 - başlangıç[a]; b++) { if (b == 8 - başlangıç[a]) System.out.printf("%d ", b); else System.out.printf("%d ", b); } başlangıç[a] = 9 - başlangıç[a]; } System.out.println(); for (int x = 0; x < 5; x++) { for (int a = 8; a < 12; a++) { for (int b = 1; b <= 7; başlangıç[a]++) { if (başlangıç[a] < 10) { if (b == 7) System.out.printf("%d ", başlangıç[a]); else System.out.printf("%d ", başlangıç[a]); } else { if (aydakigün[a] >= başlangıç[a]) { if (b == 7) System.out.printf("%d ", başlangıç[a]); else System.out.printf("%d ", başlangıç[a]); } else { if (b == 7) System.out.printf(" "); else System.out.printf(" "); } } b++; } } System.out.println(); } } }
    Java ile Takvim
    Java ile Takvim


    20.02.2024

    Kod

    Yığını:
    public class Calender { public static void main(String[] args) { int year = 2024; int start = 0; int[] dOfMonths = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; for (int i = 1; i < year; i++) { if (i % 4 != 0 || (i % 100 == 0 && i % 400 != 0)) start += 1; else {dOfMonths[1] = 29; start += 2;} start %= 7; } String[] months = {"Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"}; String leftAlignFormat = ""; int mCounter = 0; System.out.format(" " + year + " %n"); for (int t = 1; t <= 3; t++) { leftAlignFormat = "| %-7s | | %-7s | | %-7s | | %-7s |%n"; System.out.format("+----------------------------------+ +----------------------------------+ +----------------------------------+ +----------------------------------+%n"); System.out.format(leftAlignFormat, months[mCounter++], months[mCounter++], months[mCounter++], months[mCounter++]); System.out.format("|----------------------------------| |----------------------------------| |----------------------------------| |----------------------------------|%n"); System.out.format("| Pt | Sa | Ça | Pe | Cu | Ct | Pa | | Pt | Sa | Ça | Pe | Cu | Ct | Pa | | Pt | Sa | Ça | Pe | Cu | Ct | Pa | | Pt | Sa | Ça | Pe | Cu | Ct | Pa |%n"); leftAlignFormat = "| %-2s | %-2s | %-2s | %-2s | %-2s | %-2s | %-2s | | %-2s | %-2s | %-2s | %-2s | %-2s | %-2s | %-2s | | %-2s | %-2s | %-2s | %-2s | %-2s | %-2s | %-2s | | %-2s | %-2s | %-2s | %-2s | %-2s | %-2s | %-2s |%n"; int a, b, c, d; if (t == 1) { a = start; b = (a + 3) % 7; c = dOfMonths[1] == 28 ? b : (b + 1) % 7; d = (c + 3) % 7; start = (d + 2) % 7; } else if (t == 2) { a = start; b = (a + 3) % 7; c = (b + 2) % 7; d = (c + 3) % 7; start = (d + 3) % 7; } else { a = start; b = (a + 2) % 7; c = (b + 3) % 7; d = (c + 2) % 7; } int[] sM = {a, b, c, d}; int[] sW = {1, 1, 1, 1}; String[] x = new String[28]; int row = 5; for (int i = 0; i < 4; i++) { if (dOfMonths[4 * (t - 1) + i ] > (28 + (7 - sM[i]))) { row = 6; break; } } for (int i = 1; i <= row; i++) { System.out.format("|----+----+----+----+----+----+----| |----+----+----+----+----+----+----| |----+----+----+----+----+----+----| |----+----+----+----+----+----+----| %n"); int xCounter = 0; for (int k = 0; k < 4; k++) { for (int j = 0; j < 7; j++) { if (i == 1 && j < sM[k] % 7) x[xCounter++] = ""; else if (sW[k] > dOfMonths[4 * (t - 1) + k]) x[xCounter++] = ""; else x[xCounter++] = "" + sW[k]++; } } System.out.format(leftAlignFormat, x[0] , x[1] ,x[2] ,x[3] , x[4], x[5], x[6], x[7] , x[8] ,x[9] ,x[10],x[11],x[12],x[13], x[14], x[15],x[16],x[17],x[18],x[19],x[20], x[21], x[22],x[23],x[24],x[25],x[26],x[27]); } System.out.format("+----------------------------------+ +----------------------------------+ +----------------------------------+ +----------------------------------+ %n%n"); } }
    Java ile Takvim
    Java ile Takvim



    < Bu mesaj bu kişi tarafından değiştirildi Anjal -- 29 Şubat 2024; 15:9:51 >







  • benden de wpf si gelsin


    Kod

    Yığını:
    <Window x:Class="Takvim.MainWindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Takvim"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     Title="Takvim"     Width="800" Height="450"     d:DataContext="{d:DesignInstance Type=local:MainViewModel}"     RenderOptions.EdgeMode="Aliased"  WindowState="Maximized"     mc:Ignorable="d">     <Window.Resources>         <Viewbox x:Key="Bayrak" x:Shared="false">             <Canvas Width="32.000" Height="21.333">                 <Path Data=" M 0.000,0.000 L 32.000,0.000 L 32.000,21.333 L 0.000,21.333 L 0.000,0.000 Z" Fill="Red" />                 <Path Data=" M 10.667,5.330 C 12.565,5.330 14.231,6.322 15.176,7.815 C 14.395,6.945 13.262,6.397 12.001,6.397 C 9.645,6.397 7.735,8.309 7.735,10.667 C 7.735,13.025 9.645,14.936 12.001,14.936 C 13.262,14.936 14.395,14.389 15.176,13.518 C 14.231,15.012 12.565,16.004 10.667,16.004 C 7.722,16.004 5.335,13.614 5.335,10.667 C 5.335,7.719 7.722,5.330 10.667,5.330 Z" Fill="White" />                 <Path Data=" M 15.215,10.667 L 17.169,10.038 L 17.165,7.993 L 18.368,9.650 L 20.320,9.014 L 19.110,10.667 L 20.320,12.319 L 18.368,11.683 L 17.165,13.341 L 17.169,11.295 L 15.215,10.667 Z" Fill="White" />             </Canvas>         </Viewbox>         <local:YarımGünTatilConverter x:Key="YarımGünTatilConverter" />         <local:GünTatilConverter x:Key="GünTatilConverter" />         <CollectionViewSource x:Key="Data" Source="{Binding Günler}">             <CollectionViewSource.GroupDescriptions>                 <PropertyGroupDescription PropertyName="Ay" />             </CollectionViewSource.GroupDescriptions>         </CollectionViewSource>     </Window.Resources>     <Window.DataContext>         <local:MainViewModel />     </Window.DataContext>     <Grid>         <Grid.ColumnDefinitions>             <ColumnDefinition Width="Auto" />             <ColumnDefinition />             <ColumnDefinition Width="Auto" />         </Grid.ColumnDefinitions>         <Grid.RowDefinitions>             <RowDefinition Height="Auto" />             <RowDefinition />         </Grid.RowDefinitions>         <Border BorderBrush="Black" BorderThickness="1" Grid.Row="0" Grid.ColumnSpan="3">             <TextBlock Text="{Binding SeçiliYıl}" HorizontalAlignment="Center" FontWeight="Bold" />         </Border>         <Button Content="ç"             Grid.Row="1" Grid.Column="0" Grid.RowSpan="2"             FontFamily="Wingdings"             Command="{Binding Geri}" />         <ListBox Grid.Row="1" Grid.Column="1" Grid.RowSpan="2"             ItemsSource="{Binding Mode=OneWay, Source={StaticResource Data}}"             SelectedIndex="{Binding BugünIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">             <ListBox.ItemContainerStyle>                 <Style TargetType="ListBoxItem">                     <Setter Property="Margin" Value="1" />                     <Setter Property="BorderThickness" Value="0.5" />                     <Setter Property="BorderBrush" Value="#FF145CD6" />                     <Style.Triggers>                         <DataTrigger Binding="{Binding GünAdı}" Value="Cmt">                             <Setter Property="Background" Value="Yellow" />                         </DataTrigger>                         <DataTrigger Binding="{Binding GünAdı}" Value="Paz">                             <Setter Property="Background" Value="Red" />                         </DataTrigger>                         <DataTrigger Binding="{Binding Converter={StaticResource GünTatilConverter}, Mode=OneWay}" Value="true">                             <Setter Property="Background" Value="Magenta" />                         </DataTrigger>                         <DataTrigger Binding="{Binding Converter={StaticResource YarımGünTatilConverter}, Mode=OneWay}" Value="true">                             <Setter Property="Background">                                 <Setter.Value>                                     <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">                                         <GradientStop Offset="0.5" Color="Transparent" />                                         <GradientStop Offset="0.5" Color="Magenta" />                                         <LinearGradientBrush.RelativeTransform>                                             <RotateTransform Angle="45" CenterX="0.5" CenterY="0.5" />                                         </LinearGradientBrush.RelativeTransform>                                     </LinearGradientBrush>                                 </Setter.Value>                             </Setter>                         </DataTrigger>                     </Style.Triggers>                 </Style>             </ListBox.ItemContainerStyle>             <ListBox.GroupStyle>                 <GroupStyle>                     <GroupStyle.Panel>                         <ItemsPanelTemplate>                             <UniformGrid Columns="3" Rows="4" />                         </ItemsPanelTemplate>                     </GroupStyle.Panel>                     <GroupStyle.ContainerStyle>                         <Style TargetType="GroupItem">                             <Setter Property="Template">                                 <Setter.Value>                                     <ControlTemplate TargetType="{x:Type GroupItem}">                                         <Grid Margin="2">                                             <Grid.RowDefinitions>                                                 <RowDefinition Height="Auto" />                                                 <RowDefinition />                                             </Grid.RowDefinitions>                                             <Border Grid.Row="0" BorderBrush="Black" BorderThickness="1,1,1,0">                                                 <TextBlock Text="{Binding Path=Name}"                                                     Background="Green"                                                     FontWeight="Bold"                                                     TextAlignment="Center" />                                             </Border>                                             <Border Grid.Row="1" BorderBrush="Black" BorderThickness="1">                                                 <Border.Background>                                                     <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">                                                         <GradientStop Offset="0" Color="#FF146AD6" />                                                         <GradientStop Offset="1" Color="#FF146AD6" />                                                         <GradientStop Offset="0.5" Color="#FF1A75D1" />                                                     </LinearGradientBrush>                                                 </Border.Background>                                                 <ItemsPresenter />                                             </Border>                                         </Grid>                                     </ControlTemplate>                                 </Setter.Value>                             </Setter>                         </Style>                     </GroupStyle.ContainerStyle>                 </GroupStyle>             </ListBox.GroupStyle>             <ListBox.ItemTemplate>                 <DataTemplate>                     <Canvas Width="32" Height="30">                         <ContentControl Canvas.Right="0" Width="16" Height="10">                             <ContentControl.Style>                                 <Style TargetType="ContentControl">                                     <Setter Property="Content" Value="{x:Null}" />                                     <Style.Triggers>                                         <DataTrigger Binding="{Binding Converter={StaticResource GünTatilConverter}, Mode=OneWay}" Value="true">                                             <Setter Property="Content" Value="{StaticResource Bayrak}" />                                         </DataTrigger>                                     </Style.Triggers>                                 </Style>                             </ContentControl.Style>                         </ContentControl>                         <TextBlock FontSize="11">                             <Run Text="{Binding Gün}" />                             <LineBreak />                             <Run Text="{Binding GünAdı}" />                         </TextBlock>                     </Canvas>                 </DataTemplate>             </ListBox.ItemTemplate>             <ListBox.ItemsPanel>                 <ItemsPanelTemplate>                     <UniformGrid Columns="7" FirstColumn="{Binding Items[0].Offset}" />                 </ItemsPanelTemplate>             </ListBox.ItemsPanel>         </ListBox>         <Button Content="è"             Grid.Row="1" Grid.Column="2" Grid.RowSpan="2"             FontFamily="Wingdings"             Command="{Binding İleri}" />     </Grid> </Window>


    Kod

    Yığını:
    using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Globalization; using System.Linq; using System.Windows.Data; using System.Windows.Input; namespace Takvim {     public class GünTatilConverter : IValueConverter     {         private readonly List<Tuple<string, int>> tatiller = new List<Tuple<string, int>>();         public GünTatilConverter()         {             tatiller.Add(new Tuple<string, int>("Ocak", 1));             tatiller.Add(new Tuple<string, int>("Nisan", 23));             tatiller.Add(new Tuple<string, int>("Mayıs", 1));             tatiller.Add(new Tuple<string, int>("Mayıs", 19));             tatiller.Add(new Tuple<string, int>("Temmuz", 15));             tatiller.Add(new Tuple<string, int>("Ağustos", 30));             tatiller.Add(new Tuple<string, int>("Ekim", 29));         }         public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value is Data data && tatiller.Any(z => z.Item1 == data.Ay && z.Item2 == data.Gün);         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();     }           public class YarımGünTatilConverter : IValueConverter     {         private readonly List<Tuple<string, int>> tatiller = new List<Tuple<string, int>>();         public YarımGünTatilConverter() => tatiller.Add(new Tuple<string, int>("Ekim", 28));         public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value is Data data && tatiller.Any(z => z.Item1 == data.Ay && z.Item2 == data.Gün);         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();     }     public class RelayCommand : ICommand     {         private readonly Func<object, bool> canExecute;         private readonly Action<object> execute;         public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)         {             this.execute = execute;             this.canExecute = canExecute;         }         public event EventHandler CanExecuteChanged { add => CommandManager.RequerySuggested += value; remove => CommandManager.RequerySuggested -= value; }         public bool CanExecute(object parameter) => canExecute == null || canExecute(parameter);         public void Execute(object parameter) => execute(parameter);     }     public abstract class InpcBase : INotifyPropertyChanged, INotifyPropertyChanging     {         public event PropertyChangedEventHandler PropertyChanged;         public event PropertyChangingEventHandler PropertyChanging;         protected virtual void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));         protected virtual void OnPropertyChanging(string propertyName) => PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));     }     public class Data : InpcBase     {         private int gün;         private string günAdı;         private string ay;         private int offset;         public int Gün         {             get => gün;             set             {                 if (gün != value)                 {                     gün = value;                     OnPropertyChanged(nameof(Gün));                 }             }         }         public string Ay         {             get { return ay; }             set             {                 if (ay != value)                 {                     ay = value;                     OnPropertyChanged(nameof(Ay));                 }             }         }         public string GünAdı         {             get { return günAdı; }             set             {                 if (günAdı != value)                 {                     günAdı = value;                     OnPropertyChanged(nameof(GünAdı));                 }             }         }         public int Offset         {             get { return offset; }             set             {                 if (offset != value)                 {                     offset = value;                     OnPropertyChanged(nameof(Offset));                 }             }         }     }     public class MainViewModel : InpcBase     {         private ObservableCollection<Data> günler;         public ObservableCollection<Data> Günler         {             get { return günler; }             set             {                 if (günler != value)                 {                     günler = value;                     OnPropertyChanged(nameof(Günler));                 }             }         }         private int seçiliYıl = DateTime.Now.Year;         private int bugünIndex = DateTime.Today.DayOfYear - 1;         public int SeçiliYıl         {             get { return seçiliYıl; }             set             {                 if (seçiliYıl != value)                 {                     seçiliYıl = value;                     TakvimOluştur();                     OnPropertyChanged(nameof(SeçiliYıl));                 }             }         }         public int BugünIndex         {             get { return bugünIndex; }             set             {                 if (bugünIndex != value)                 {                     bugünIndex = value;                     OnPropertyChanged(nameof(BugünIndex));                 }             }         }         public MainViewModel()         {             TakvimOluştur();             Geri = new RelayCommand(parameter => SeçiliYıl--, parameter => SeçiliYıl > 1);             İleri = new RelayCommand(parameter => SeçiliYıl++, parameter => SeçiliYıl < 9999);         }         public ICommand Geri { get; }         public ICommand İleri { get; }         private void TakvimOluştur()         {             Günler = new ObservableCollection<Data>();             for (int i = 1; i <= 12; i++)             {                 for (int j = 1; j <= 31; j++)                 {                     string tarih = $"{SeçiliYıl}-{i}-{j}";                     if (DateTime.TryParse(tarih, out _))                     {                         var data = new Data                         {                             GünAdı = DateTime.Parse(tarih).ToString("ddd"),                             Gün = DateTime.Parse(tarih).Day,                             Ay = DateTime.Parse(tarih).ToString("MMMM"),                             Offset = (int)(DateTime.Parse(tarih).DayOfWeek)                         };                         Günler.Add(data);                     }                 }             }         }     } }

    https://github.com/goksenpasli/Takvim




    < Bu mesaj bu kişi tarafından değiştirildi Gökşen PASLI -- 17 Kasım 2022; 17:50:23 >




  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.