פתרון תרגילי כיתה בקלפים. תחלק 5 קלפים ותחשב את הסכום של כל הקלפים class Program { static void Main(string[] args) { Deck hafisa = new Deck(); // Card.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

For(int i = 1; i
מבוא למדעי המחשב לתעשייה וניהול
EXAMPLES. Example 1: Write a Java method that performs addition on two binary numbers. Each binary number is kept in an integer array
Static. שינוי במחלקה DECK static private Card[] deck;
תכנות ב C#. דוגמא לפלט using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void.
פתרון בוחן הכיתה. שאלה #1 Module Module1 Sub Main() Dim x, z As Integer x = Console.ReadLine() z = Console.ReadLine() If (x = 0) Then Console.WriteLine("Error")
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים 1 הפניות.
o Simulate a deck of playing cards o Shuffle the deck o Deal (5) cards into the hand o Turn over the first card o The user must guess whether the next.
o Simulate a deck of playing cards o Shuffle the deck o Deal 5 cards into the hand o Turn over the first card o The user must guess whether the next card.
LAB 10.
Computer Programming Lab(4).
Do You Understand Methods and Parameters? In this section you will be shown 25 different programs. Most of these programs have some type of error. A few,
Computer Programming Lab(5).
Shorthand operators.
Kids, JavaScript, and Minecraft an explosive combination greg bulmash – cascadiajs 2015
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
תרגול 13 חזרה 1. Exam example 8 public class Stam { private char x; public Stam() { this.x = '*'; } public Stam (char c) { this.x = c; } public Stam getStam()
Mixing integer and floating point numbers in an arithmetic operation.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
The Assignment operator tMyn1 The Assignment Operator The result of a calculation can be stored in a variable using the assignment operator =. Because.
Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have 45 – 90 seconds per question. Determine the output.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
1 מבוא למדעי המחשב הרצאה 5: פונקציות. 2 מבוא לפונקציות חלוקה של אלגוריתם לתת משימות: משימה - פונקציה: דוגמאות מציאת המקסימלי מבין שני איברים האינדקס של.
1 Printing characters : Revisited class printcharacter{ public static void main(String arg[]){ char grade=‘A’; System.out.println(grade);// prints A System.out.println((int)grade);
CS001 Introduction to Programming Day 6 Sujana Jyothi
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true;
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Staples are our staple Building upon our solution.
Three kinds of looping structures The while loop The for loop The do (also called the do-while) loop All have equivalent power, e.g., if you can write.
Department of Computer Science
התוכנית: using System; using System.Collections.Generic;
Algorithms and programming
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Function Call Trace public class Newton {
Something about Java Introduction to Problem Solving and Programming 1.
Decision statements. - They can use logic to arrive at desired results
Functions Used to write code only once Can use parameters.
Computing Adjusted Quiz Total Score
חלק ה שימוש במציין שלם לערך תווי
Propositional Equivalences Rosen 5th and 6th Editions section 1.2
محاور المحاضرة خوارزمية الفقاعات الهوائية (Bubble Sort)
מבוא לתכנות ב- Java תרגול 10 - רשימות מקושרות.
Code Animation Examples
References, Objects, and Parameter Passing
Method Overloading in JAVA
Recursive GCD Demo public class Euclid {
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
if-else if (condition) { statements1 } else { statements2
Module 3 Selection Structures 4/3/2019 CSE 1321 Module 3.
Methods and Data Passing
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
while while (condition) { statements }
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Consider the following code:
CIS 110: Introduction to Computer Programming
I have… I have… Who has 3:40? Who has 12:20? I have… I have…
CSC 205 Java Programming II
Instructor: Mainak Chaudhuri
Presentation transcript:

פתרון תרגילי כיתה בקלפים

תחלק 5 קלפים ותחשב את הסכום של כל הקלפים class Program { static void Main(string[] args) { Deck hafisa = new Deck(); // Card me; int sum_me = 0, i; for (i = 0; i < 5; i++) // { me = hafisa.dealCard(); sum_me += me.getValue(); } Console.WriteLine("The sum of your first {0} cards is: {1}", i, sum_me); }

תחלק 5 קלפים ותחשב את הסכום של כל הקלפים class Program { static void Main(string[] args) { Deck hafisa = new Deck(); // Card me; int sum_me = 0, i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) // { me = hafisa.dealCard(); my_hand.addCard(me); sum_me += me.getValue(); } Console.WriteLine("The sum of your first {0} cards is: {1}", i, sum_me); }

פתרון נוסף static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int sum_me = 0, i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } for (i = 0; i < my_hand.getCardCount(); i++) // { me = my_hand.getCard(i);//first get card sum_me += me.getValue();//now add it to the sum } Console.WriteLine("The sum of your first {0} cards is: {1}", i, sum_me); }

פתרון נוסף static void Main(string[] args) { Deck hafisa = new Deck(); // Card me; int sum_me = 0, i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) // { me = hafisa.dealCard(); my_hand.addCard(me); } for (i = 0; i < my_hand.getCardCount(); i++) // { sum_me += my_hand.getCard(i).getValue();//What??? } Console.WriteLine("The sum of your first {0} cards is: {1}", i, sum_me); }

תוסיף קלף חדש לסוף הHAND של 5 קלפים static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } for (i = 0; i < my_hand.getCardCount(); i++) { me = my_hand.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } me = hafisa.dealCard(); my_hand.addCard(me);//where did it go??? for (i = 0; i < my_hand.getCardCount(); i++) { me = my_hand.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); }

פתרון יותר טוב (עם פונקציה) class Program { static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); me = hafisa.dealCard(); my_hand.addCard(me);//where did it go??? Print(my_hand); }

פתרון יותר טוב (עם פונקציה) static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } for (i = 0; i < my_hand.getCardCount(); i++) { me = my_hand.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } me = hafisa.dealCard(); my_hand.addCard(me);//where did it go??? for (i = 0; i < my_hand.getCardCount(); i++) { me = my_hand.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); }

תוריד את הקלף הראשון מתוך הHAND static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); my_hand.removeCard(0); Print(my_hand); }

פתרון נוסף static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); me = my_hand.getCard(0); my_hand.removeCard(me); Print(my_hand); }

תוריד את הקלף הראשון מתוך הHAND static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); my_hand.removeCard(0); Print(my_hand); }

תוריד את הקלף האחרון מתוך הHAND static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); int temp = my_hand.getCardCount(); me = my_hand.getCard(temp - 1); my_hand.removeCard(me); Print(my_hand); }

פתרון נוסף static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 5; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); my_hand.removeCard(my_hand.getCardCount()-1); Print(my_hand); }

תוריד כל קלף שני (זוגי) מתוך הHAND static void Print(Hand x) { for (int i = 0; i < x.getCardCount(); i++) { Card me = x.getCard(i); Console.WriteLine("The card in position {0} is {1} ", i, me.toString()); } static void Main(string[] args) { Deck hafisa = new Deck(); Card me; int i; Hand my_hand = new Hand(); for (i = 0; i < 10; i++) { me = hafisa.dealCard(); my_hand.addCard(me); } Print(my_hand); for (i = 0; i < my_hand.getCardCount(); i++) { if (i % 2 == 0) // mod 2 means it is even my_hand.removeCard(i); } Print(my_hand); }