Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
contact_manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SECOND
java
contact_manager
Commits
adbc2560
Commit
adbc2560
authored
2 years ago
by
jonas.stirnema
Browse files
Options
Downloads
Patches
Plain Diff
Added class, basic getter and setters
parent
e47d5291
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Contact.java
+95
-0
95 additions, 0 deletions
src/Contact.java
src/DynArray.java
+84
-0
84 additions, 0 deletions
src/DynArray.java
src/Main.java
+7
-3
7 additions, 3 deletions
src/Main.java
with
186 additions
and
3 deletions
src/Contact.java
0 → 100644
+
95
−
0
View file @
adbc2560
public
class
Contact
{
// Attributes
private
String
fname
;
private
DynArray
names
;
private
String
address
;
private
DynArray
phoneNumbers
;
private
DynArray
emails
;
private
DynArray
socials
;
private
String
job
;
public
String
getFname
()
{
return
fname
;
}
public
void
setFname
(
String
fname
)
{
if
(!
fname
.
isBlank
())
{
this
.
fname
=
fname
;
}
else
{
this
.
fname
=
"Anon"
;
}
}
public
DynArray
getNames
()
{
return
names
;
}
public
void
setNames
(
DynArray
names
)
{
if
(!
names
.
isEmpty
())
{
this
.
names
=
names
;
}
else
{
this
.
names
=
new
DynArray
(
new
String
[]
{
"Anon"
});
}
}
public
String
getAddress
()
{
return
address
;
}
public
void
setAddress
(
String
address
)
{
if
(!
address
.
isBlank
())
{
this
.
address
=
address
;
}
else
{
this
.
address
=
"Nowhere"
;
}
}
public
DynArray
getPhoneNumbers
()
{
return
phoneNumbers
;
}
public
void
setPhoneNumbers
(
DynArray
phoneNumbers
)
{
if
(!
phoneNumbers
.
isEmpty
())
{
this
.
phoneNumbers
=
new
DynArray
(
new
String
[]
{
"0102030405"
});
}
}
public
DynArray
getEmails
()
{
return
emails
;
}
public
void
setEmails
(
DynArray
emails
)
{
if
(!
emails
.
isEmpty
())
{
this
.
emails
=
new
DynArray
(
new
String
[]
{
"none@none.com"
});
}
}
public
DynArray
getSocials
()
{
return
socials
;
}
public
void
setSocials
(
DynArray
socials
)
{
if
(!
socials
.
isEmpty
())
{
this
.
socials
=
socials
;
}
else
{
this
.
socials
=
new
DynArray
(
new
String
[]
{
"@anon"
});
}
}
public
String
getJob
()
{
return
job
;
}
public
void
setJob
(
String
job
)
{
if
(!
job
.
isBlank
())
{
this
.
job
=
job
;
}
else
{
this
.
job
=
"none"
;
}
}
}
This diff is collapsed.
Click to expand it.
src/DynArray.java
0 → 100644
+
84
−
0
View file @
adbc2560
public
class
DynArray
{
private
final
int
basev
=
10
;
private
int
size
=
0
;
private
String
[]
array
;
private
int
capacity
;
public
DynArray
(
String
[]
a
)
{
this
.
size
=
a
.
length
;
this
.
capacity
=
this
.
basev
;
this
.
array
=
new
String
[
this
.
capacity
];
copy_content
(
a
,
this
.
array
);
}
public
DynArray
()
{
this
.
array
=
new
String
[
this
.
capacity
];
this
.
size
=
0
;
}
public
void
append
(
String
[]
a
)
{
make_sure_size
(
a
);
// REALLOC IF NEEDED
this
.
size
+=
a
.
length
;
int
s
=
this
.
size
;
// Add the new values
for
(
int
i
=
s
;
i
<
s
+
a
.
length
;
i
++)
{
// System.out.println("arr[" + (i - a.length) + "] = " + a[i - s]);
this
.
array
[
i
-
a
.
length
]
=
a
[
i
-
s
];
}
}
public
void
pop
()
{
if
(
this
.
size
<
1
)
{
System
.
err
.
println
(
"Cannot remove from an epmty list"
);
return
;
}
this
.
size
--;
}
public
void
make_sure_size
(
String
[]
a
)
{
if
((
this
.
size
+
a
.
length
)
>
this
.
capacity
)
// Overflow?
{
// Realloc new array
this
.
capacity
*=
2
;
String
[]
new_arr
=
new
String
[
this
.
capacity
];
copy_content
(
this
.
array
,
new_arr
);
this
.
array
=
new_arr
;
// Copy pointer
}
}
public
void
show_it
()
{
System
.
out
.
println
(
this
.
intoString
());
}
public
String
intoString
()
{
String
s
=
"[ "
;
for
(
int
i
=
0
;
i
<
this
.
size
;
i
++)
{
s
=
s
.
concat
(
array
[
i
]);
s
=
s
.
concat
(
", "
);
}
s
=
s
.
concat
(
" ]"
);
return
s
;
}
public
boolean
isEmpty
()
{
return
size
==
0
;
}
private
static
void
copy_content
(
String
[]
source
,
String
[]
dest
)
{
// System.out.println("Source lenght" + source.length);
// System.out.println("Dest lenght" + dest.length);
if
(
source
.
length
>
dest
.
length
)
{
throw
new
Error
(
"Cannot copy : second array smaller than first"
);
}
for
(
int
i
=
0
;
i
<
source
.
length
;
i
++)
{
dest
[
i
]
=
source
[
i
];
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Main.java
+
7
−
3
View file @
adbc2560
package
src
;
public
class
Main
{
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hey"
);
DynArray
ar1
=
new
DynArray
(
new
String
[]
{
"Test"
,
"Test2"
,
"Test3"
});
ar1
.
show_it
();
ar1
.
append
(
new
String
[]
{
"Test4"
,
"Test5"
,
"Test6"
});
ar1
.
show_it
();
ar1
.
pop
();
ar1
.
show_it
();
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment