Skip to content
Open

Lab3 #60

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions ContactList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package kz.edu.nu.cs.exercise;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class ContactList {
private List<MyContact> list;

public ContactList() {
list = new ArrayList<MyContact>();
}

public static ContactList MakeContactList(String s) {
Gson gson = new Gson();
ContactList g = gson(s,ContactList.class);
return g;
}


public void addContact(MyContact c) {
list.add(c);
}

public void removeFirstContact() {
list.remove(0);
}

public MyContact getFirstContact() {
return list.get(0);
}

public int getSize() {
return list.size();
}
}

46 changes: 46 additions & 0 deletions MyContact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package kz.edu.nu.cs.exercise;

import com.google.gson.Gson;

public class MyContact {
private String name;
private int age;
private String number;

public MyContact(String name, int age, String number) {
this.name = name;
this.age = age;
this.number = number;
}

public static MyContact MakeMyContact(String s) {
Gson gson = new Gson();
MyContact g = gson.fromJson(s, MyContact.class);
return g;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

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

public String getNumber() {
return number;
}

public void setNumber(String number) {
this.number = number;
}
}

10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>


import org.json.JSONException;
import org.json.JSONObject;

<groupId>kz.edu.nu.cs</groupId>
<artifactId>jsonexercise-361</artifactId>
<version>0.0.1-SNAPSHOT</version>
Expand All @@ -22,7 +24,11 @@
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>

<build>
Expand Down