Hirdetés

Keresés

Új hozzászólás Aktív témák

  • Azazello-
    senior tag

    koszonom szepen a segitseget mindenkinek.

    nem erettsegi, csak alap programozas.

  • Azazello-
    senior tag

    sziasztok,

    vizsgahoz kellene par egyszeru kerdesre megdnom a valaszt, de sajna meg mindig nem megy magamtol. valaki segitene megoldani az alabbi problemakat?

    1,

    String[] myArray = {“Jan”,”Feb”,”Mar”,”Apr”};
    Loop true and print them out:

    ---------------------------

    2,

    • Test for String equality
    String S1 = “One”;
    String S2 = “One”;

    -----------------

    3,

    Storing primitives in an ArrayList
    charValue
    public char charValue()
    - Returns the value of this Character object.
    - Returns: the primitive char value represented by this object.

    ----------------------

    4,

    - Loop over a String

    erre nem tudom, hogy jo e a megoldas...:

    ArrayList=al
    Arrasy=ar

    Al.size();
    Ar.lenght;

    For(int i=0; i< ar.lenght; i++)

    ----------------

    5,

    Write a method to verify if the numbers of a series are in ascending order

    Int[] num = {1,2,6,5};

    Private boolean checkSort(int[] x){

    for(int i=0; i < x.length; i++)

    if(???)

    }

    -----------------------

    6,

    HashMap
    - Add to a HashMap
    - Delete from a HashMap
    - Does it contain a practicular key?

    ------------------------

    ezekre kene a valasz, illetve megoldas. koszonom elore is. :U

  • Azazello-
    senior tag

    egy bűn ronda és egyszerhasználatos megoldás :) (talán ehhez kell a legkevesebb pluszt hozzátenni ill. módosítani a kódban):
    Numbers osztályban egy új függvény:
    (nem kiírja a sort mint a printLine(), hanem String-et épít belőle - és az utolsó szám után nem tesz space-t)

    public String getLine() {
    String ret = "";
    for(int i=0;i<index.length;i++){
    ret += String.format("%2d" + (i==index.length-1?"":" "), index[i]);
    }
    return ret;
    }

    Tickets osztályban kiíratás pedig:
    itt ugye "bele van égetve" a programkódba, hogy hol milyen karakterből mennyi legyen (még szerencse hogy a sorok mindig egyforma hosszúak)

    public void printTicket(){
    System.out.println("* * * * * * * * * * * * * *");
    System.out.println("** **");
    System.out.println("** Lottery Tickets **");
    System.out.println("** **");
    System.out.println("* * * * * * * * * * * * * *");
    for (Numbers n : lottoLines) {
    System.out.println("** " + n.getLine() + " **");
    }
    System.out.println("* * * * * * * * * * * * * *");
    }

    persze lehet sokkal szebben meg univerzálisabban, de egy ekkora példánál felesleges szerintem

    koszonom szepen a segitseget!

  • Azazello-
    senior tag

    én is értem a feladatot (:D), csak arra akartam rámutatni, hogy a jelenlegi printline() implementációval ez nem fog menni, de egyébként egyszerű megoldani
    az elméletével van a gond vagy a konkrét megvalósítással?

    oszinten szolva mindket reszevel

  • Azazello-
    senior tag

    a Numbers osztály printline() függvénye új sort kezd, így nehéz lesz a csillagot odavarázsolni a sor végére utólag :)
    ha ettől eltekintünk, a "%2d " miatt ugye mindig egyforma hosszú sorokat ír ki, szóval előre lehet tudni hogy hány db csillag vagy space kell a keret soraiba

    ezt ertem, hogy elotte es utana csillagozni lehet, de nekem ugy van megadva a feladat, hogy korbe legyen veve csillagokkal.

  • Azazello-
    senior tag

    public void printTicket(){
    System.out.println("* * * * * * * * * * * * * *");
    System.out.println("** **");
    System.out.println("** Lottery Tickets **");
    System.out.println("** **");
    System.out.println("* * * * * * * * * * * * * *");
    //access each element of the arrayList and call its printLine() method
    for (Numbers n : lottoLines)
    {
    n.printLine();
    }
    }

    néha rádupláz szerkesztésnél :/

    ezt a kodot hogyan lehetne egy keretbe foglalni?

    *************************
    * *
    * ide jonnne a ticket *
    * *
    *************************

    valahogy igy

  • Azazello-
    senior tag

    public void printTicket(){
    System.out.println("* * * * * * * * * * * * * *");
    System.out.println("** **");
    System.out.println("** Lottery Tickets **");
    System.out.println("** **");
    System.out.println("* * * * * * * * * * * * * *");
    //access each element of the arrayList and call its printLine() method
    for (Numbers n : lottoLines)
    {
    n.printLine();
    }
    }

    néha rádupláz szerkesztésnél :/

    koszi :B

  • Azazello-
    senior tag

    biztos vagy benne, hogy a nyomtas alatt tenyleges nyomtatasra gondolnak, es nem csak siman a kepernyore kiiratas? (az is print....)

    de, kepernyorekiiras kene

  • Azazello-
    senior tag

    sziasztok, segitseget szeretnek kerni, hazi feladat megoldasa kozben elakadtam.

    egy lottoszam sorsolo programot kell keszitenem.
    ket class van, Ticket es Numbers. a numbers class kisorsol 6 szamot es sorrendbe allitja oket. a ticket classnal pedig meg kene oldanom, hogy adott mennyisegu tickettet lehessen kerni, es azokat ki is leessen nyomtatni.

    a nyomtatas reszenel akadtam el.

    Numbers class:

    public class Numbers
    {
    //fields
    private Random randomNumber;
    private int[] index;
    private final int MAX = 6;
    private final int MAXSIZE = 49;


    // Constructor : Initialise number array
    public Numbers(){
    index = new int[MAX];
    randomNumber = new Random();
    generateNumber(MAXSIZE);
    sortNum();
    }

    // Method : Generate 6 random numbers in a range 1 to 49
    public void generateNumber(int n){
    for(int i=0;i<MAX;i++){
    index[i] = randomNumber.nextInt(n) + 1;
    for(int k=0;k<i;k++){
    if(index[k] == index[i]){
    i--;
    break;
    }
    }

    }
    }

    // Method : Sort 6 numbers in ascending order


    public void sortNum(){
    int t;
    //outer loop - j number of passes
    for(int j=0;j<index.length;j++){
    //inner loop - one pass
    for(int i=0;i<index.length-1;i++){

    if (index[i] > index[i+1]){

    t = index[i];

    index[i] = index[i+1];
    index[i+1] = t;
    }
    }
    }
    }

    // Method : Format and display 6 numbers to the screen
    public void printLine(){
    for(int i=0;i<index.length;i++){
    System.out.printf("%2d ",index[i]);
    }
    System.out.println();
    }


    }

    Ticket class:

    public class Ticket
    {
    private int numberOfLines;
    private ArrayList<Numbers> lottoLines;


    // Constructor : Creates an arrayList of Lucky Dip numbers, takes one argument to load the numberOfLines field.
    public Ticket(int numOfLines){
    lottoLines = new ArrayList<Numbers>();
    for(int i=0;i<numOfLines;i++){
    lottoLines.add(new Numbers());
    }

    }
    // Method : Display the ticket details and the list of Lucky Dip numbers to the screen.
    public void printTicket(){
    System.out.println("* * * * * * * * * * * * * *");
    System.out.println("** **");
    System.out.println("** Lottery Tickets **");
    System.out.println("** **");
    System.out.println("* * * * * * * * * * * * * *");
    //access each element of the arrayList and call its printLine() method
    }
    }

    a kerdes annyi volna, hogy hogyan tudom kinyomtattatni a kert ticketteket?

    koszonom

  • Azazello-
    senior tag

    huhh.... remelem nem fogsz nagyon meglepodni, vagy nem ertettem felre a kerdest angyon

    if (ticketsLeft) {
    // van jegy
    } else {
    //nincs jegy
    }

    tulajdonkeppen ugyan az mind minden mas if satement ha jol ertem.
    mikor a suliban kerdeztem, azt mondtak, hogy ez vlami bonyolult megoldas. :)

    koszi

  • Azazello-
    senior tag

    megprobalom maskepp feltenni a kerdest :)

    boolian if statementet hogyan kell?

    ticket available true/false-ot kene beallitanom, hogy ha nincs tobb ticket, akkor nyomtassa ki, hogy "sold out"...

  • Azazello-
    senior tag

    lehetseges e egy boolian validation es ha igen, akkor hogyan?

    /**
    * This is my Concert class it contains informations about year, location and are there any ticket left.
    *
    * @author ()
    * @version (10/12/09)
    */


    public class Concert
    {
    private int year;
    private String location;
    private boolean ticketsLeft;
    //Fields

    public Concert(int conYear, String lct,boolean ticketAv){
    year=conYear;
    //this next line of code will call the method that will validate the information that is has been imput by the user
    setLocation(lct);
    ticketsLeft=ticketAv;
    }

    public Concert(){
    year=0;
    location="";
    ticketsLeft=false;
    }

    //accessors
    public int getYear(){
    return year;
    }
    public String getLocation(){
    return location;
    }
    public boolean getTicketsLeft(){
    return ticketsLeft;
    }

    //mutators
    public void setYear(int conYear){
    year =conYear;
    }
    public void setLocation(String lct){
    // the next line of code validates that the user has typed in "brighton Hastings or London"
    if(lct.equals ("Brighton") || lct.equals("Hastings") || lct.equals("London")){
    location = lct;
    }
    else{
    //the next line of code print out a message when "Brighton Hastings or London" hasn't been typed
    System.out.println("Valid locations: Brighton, Hastings, London");
    }
    }

    public void setTicketsLeft(boolean ticketAv){
    ticketsLeft = ticketAv;
    }

    //the next method will print out the Concert details
    public void printConcert(){
    System.out.println("Location: "+location);
    System.out.println("Year :"+year);
    System.out.println("Tickets Left: "+ticketsLeft);
    }



    }

  • Azazello-
    senior tag

    idaig sikerult eljutnom _asszem_ jol:

    concert:

    /**
    * Write a description of class Concert here.
    *
    *
    */
    public class Concert
    {
    private int year;
    private String location;
    private boolean ticketsLeft;
    //Fields

    public Concert(int y, String l,boolean t){
    year=y;
    location=l;
    ticketsLeft=t;
    }

    public Concert(){
    year=0;
    location="";
    ticketsLeft=false;
    }

    //accessors
    public int getYear(){
    return year;
    }
    public String getLocation(){
    return location;
    }
    public boolean getTicketsLeft(){
    return ticketsLeft;
    }

    //mutators
    public void setYear(int y){
    year =y;
    }
    public void setLocation(String s){
    location = s;
    }
    public void setTicketsLeft(boolean b){
    ticketsLeft = b;
    }

    public void printConcert(){
    System.out.println("Location: "+location);
    System.out.println("Year :"+year);
    System.out.println("Tickets Left: "+ticketsLeft);
    }

    }

    CD:

    /**
    * A class that maintains information on a CD.
    *
    *
    */

    public class CD
    {
    // The fields.
    private Artist performer;

    private String album;
    private String genre;
    private int numberOfTracks;
    private int yearReleased;

    /*
    *Create two constructors - one to take arguments for all fields - one that takes none.
    */
    public CD (String a, String g, int tr, int y){

    album=a;
    genre=g;
    numberOfTracks=tr;
    yearReleased=y;
    }

    public CD(){

    album="";
    genre="";
    numberOfTracks=0;
    yearReleased=0;

    }
    //accessor methods
    public String getAlbum(){
    return album;
    }

    public String getGenre(){
    return genre;
    }

    public int getTracks(){
    return numberOfTracks;
    }

    public int getYear(){
    return yearReleased;
    }

    // mutator methods

    public void getAlbum(String a){
    album = a;
    }

    public void getgenre(String g){
    genre = g;
    }

    public void getTracks(int tr){
    numberOfTracks=tr;
    }

    public void getYear(int y){
    yearReleased=y;
    }

    //print the details of the CD to the console

    public void printCD(){
    System.out.println("Album Title "+album);
    System.out.println("Album Genre "+genre);
    System.out.println("Number of Tracks "+numberOfTracks);
    System.out.println("Year Relased "+yearReleased);
    }
    }

    Artist:

    /**
    * Write a description of class Artist here.
    *

    */
    public class Artist
    {
    // instance variables
    private String firstname;
    private String lastname;
    private int age;
    private Concert nextConcert;

    /**
    * Constructor(s) for objects of class Artist
    */

    public Artist (String fName, String lName, int artistAge, Concert nextConcert){
    firstname=fName;
    lastname=lName;
    age=artistAge;
    nextConcert = new Concert();
    }

    public Artist(){
    firstname="";
    lastname="";
    age=0;
    nextConcert = new Concert();
    }

    /**
    * accessor methods
    */
    public String getName(){
    return firstname;
    }

    public String getlName(){
    return lastname;
    }

    public int getAge(){
    return age;
    }

    /**
    * mutator methods
    */
    public void printArtist(){
    nextConcert.printConcert();

    }

    }

  • Azazello-
    senior tag

    egyelore ez a Concert:

    /**
    * Write a description of class Concert here.
    *
    * @author (your name)
    * @version (a version number or a date)
    */
    public class Concert
    {
    private int year;
    private String location;
    private boolean ticketsLeft;
    //Fields

    public Concert(int y, String l,boolean t){
    year=y;
    location=l;
    ticketsLeft=t;
    }

    public Concert(){
    year=0;
    location="";
    ticketsLeft=false;
    }

    //accessors
    public int getYear(){
    return year;
    }
    public String getLocation(){
    return location;
    }
    public boolean getTicketsLeft(){
    return ticketsLeft;
    }

    //mutators
    public void setYear(int y){
    year =y;
    }
    public void setLocation(String s){
    location = s;
    }
    public void setTicketsLeft(boolean b){
    ticketsLeft = b;
    }

    public void printConcert(){
    System.out.println("Locatio: "+location);
    System.out.println("Year :"+year);
    System.out.println("Tickets Left: "+ticketsLeft);
    }

    }

    es ez az Artist:

    /**
    * Write a description of class Artist here.
    *
    * @author (Oliver Szotyori)
    * @version (01/12/09)
    */
    public class Artist
    {
    // instance variables
    private String firstname;
    private String lastname;
    private int age;
    private Concert nextConcert;

    /**
    * Constructor(s) for objects of class Artist
    */

    public Artist (String fName, String lName, int artistAge, Concert nConcert){
    firstname=fName;
    lastname=lName;
    age=artistAge;
    nextConcert = new Concert();

    }

    public Artist(){
    firstname=null;
    lastname=null;
    age=0;
    nextConcert = new Concert();
    }

    /**
    * accessor methods
    */

    /**
    * mutator methods
    */
    public void printArtist(){
    nextConcert.printConcert();

    }

    }

    hogyan adom hozza, hogy az artist kinyomtassa a concert reszleteit is??

  • Azazello-
    senior tag

    no, hát egy kicsit más mint gondoltam, de mind1

    1: kell ugye egy Concert osztály, olyan tagváltozókkal, amiket te döntesz el mi lehet, legyen pl. a koncert éve, és helye

    class Concert
    {
    private int year;
    private string location;
    }

    2: egy üres konstruktor, és paraméteres konstruktor, előbbi példánál maradva

    class Concert
    {
    private int year;
    private String location;

    public Concert()
    {
    // ide jöhet pl. a default értékek beállítása
    }

    public Concert(int year, String location)
    {
    this.year = year;
    this.location = location;
    }
    }

    a többi osztály ugyanígy

    3: ugye privát tagváltozók vannak, nem szeretnénk, hogy mindenki kedvére módosítgassa őket, ezért van külön getter/setter (vagy accessor/mutator) metódus, ahol korlátozhatjuk a módosítást/elérést

    például Artist osztály:

    public class Artist
    {
    ...
    private int age;
    ...

    public void setAge(int age) { this.age = age; }
    public int getAge() { return this.age; }
    }

    összes többi tagváltozóra ugyanígy

    4: print method, elég egyértelmű sztem
    System.out.println(...) és mehet az, amit épp ki kell írni
    a változóknak adsz mondjuk default 0/null értéket, és ez alapján lehet vizsgálni, hogy be vannak-e állítva

    5: az itt leírt szabályokat kell megvalósítani
    elég mondjuk a setter részben, és ha már úgyis meg van írva, akkor lehet konstruktorban is azt használni
    pl. írja, hogy az Artist kora több mint 0, és kevesebb mint 120
    ennek megfelelően kell megírni a settert + a konstruktort hozzáigazítani

    public class Artist
    {
    private int age;

    public void setAge(int age)
    {
    if ((age > 0) && (age <120)) this.age = age;
    }
    public int getAge() { return this.age; }

    // konstruktor módosítása
    public Artist(..., int age, ...)
    {
    ...
    setAge(age);
    ...
    }

    }

    kezdjuk elorol: mi kerul a CD-be? :F

    oda kene 2 constructor eloszor.

    // The fields.
    private Artist performer;

    private String album;
    private String genre;
    private int numberOfTracks;
    private int yearReleased;

    /*
    *Create two constructors - one to take arguments for all fields - one that takes none.
    */
    public Artist(int sAlbum,int Sgenre){

    valahogy igy kene kezdeni???

  • Azazello-
    senior tag

    jó, hát én ebből ezt hámoztam ki:

    van egy CD osztályod, amiben van egy lista, amiben a számok előadói (Artist) vannak
    maga az előadó is egy osztály, őbenne a koncertjeiről van lista (a koncert is osztály)

    1. feladat: koncertnek lehet például ideje (évszám) és helye
    2: egyértelmű, 2-2 konstruktor mindhez
    3: a privát tagváltozókhoz getter/setter (lekérdező/beállító) metódusok
    4: print: egyértelmű, le is írja, hogy mit kell kiírni
    5: a tagváltozókra vonatkozó szabályokat a setter metódusban/konstruktorban meg kell valósítani

    cd:

    class CD
    {
    // The fields.
    private Artist performer;

    private String album;
    private String genre;
    private int numberOfTracks;
    private int yearReleased;

    /*
    *Create two constructors - one to take arguments for all fields - one that takes none.
    */
    public Artist(int sAlbum,int Sgenre){

    Artist

    public class Artist
    {
    // instance variables
    private String firstname;
    private String lastname;
    private int age;
    private Concert nextConcert;

    ennyi va megadva, es ebbol kene kihoznom vlamit.

    ha legalabb a CD-nel tudnal segiteni,hogy hogyan epitsem fel, akkor abbol talan meg tudom oldani a masik kettot is.

  • Azazello-
    senior tag

    sziasztok!

    nem vagyok benne biztos, hogy jo helyen jarok, bluej projecthez kellene egy kis segitseg, de nem igazan tudom, hogy kihez forduljak, melyik volna a megfelelo topic.

    teljesen basic feladat:

    Tasks
    You have been provided with a BlueJ project file and accompanying class templates for a simple system to hold and manipulate information regarding a Compact Disc.

    The following Class diagram describes the relationship between the supplied class templates.


    [link]

    Assignment Tasks

    1. Think about the data requirements for a Concert class. Add the relevant fields to the Concert class.
    2. Create two constructors for each class - one to take arguments for all fields - one that takes none.
    3. Add accessor and mutator methods as required to all three classes.

    4. Add a print method to each class.
    • These methods should print to the terminal window.
    • For the CD class, add a print method that will print details of the CD, Artist and the artist’s next concert.
    • For any field not yet set, output an appropriate message (e.g. ‘Details not yet received’).

    5. Apply the following validation rules to class fields:
    • CD
    • private String genre – restricted to ‘Soul’, ‘Jazz’, or ‘Blues’
    • private int numberOfTracks – must be greater than zero.
    • private int yearReleased – must be a value greater than 1900 but less than 2004

    • Artist
    • private int age – must be greater than zero and less than 120

    • Concert
    • Devise and implement validation rules based on your choice of fields for this class

    -----------------------

    ebben kene nekem segitseg, mert sajna azt sem tudom, hogy hol kezdjem el :o(

    elore is koszi.

Új hozzászólás Aktív témák

Hirdetés