Monday, July 19, 2021

CH 6 iOS

Here is my UIViewController class:

//
//  ViewController.swift
//  CH6Ex1Circle
//
//  Created by stu2017 on 10/24/17.
//  Copyright © 2017 stu2017. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var tbRad: UITextField!
    @IBOutlet weak var lblCirc: UILabel!
    @IBOutlet weak var lblArea: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func btnCalc(_ sender: UIButton) {
        let rad=Double(tbRad.text!);
        let circ1=Circle(radius:rad!);
        let a=String(format: "%.2f", circ1.getArea());
        let c=String(format: "%.2f", circ1.getCircumference());
        lblArea.text="Area: \(a)";
        lblCirc.text="Circumfrence: \(c)";
    }
}

 Here is my circle class
//
//  Circle.swift
//  CH6Ex1Circle
//
//  Created by stu2017 on 10/24/17.
//  Copyright © 2017 stu2017. All rights reserved.
//

import Foundation


class Circle {
    var radius = 0.0
    
    init(radius: Double) { // Constructor
        self.radius = radius
        
    }
    var Area: Double{
        return 3.14*(radius*radius)
    }
    
    func getArea() -> Double {
        return 3.14*(radius*radius)
    }
    
    var Circumference: Double {
        return 2*3.14*radius
    }
    func getCircumference() -> Double{
        return 2*3.14*radius
    }
}

Monday, February 8, 2021

Unit 5 Chapter 3Android Intro Hello World Button

package com.example.hellobuttonweek5;//this line is unique to your app
import androidx.appcompat.app.AppCompatActivity;

import android.content.res.Resources;
import android.os.Bundle;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initButton();
initButtonClear();

}

private void initButton() {
Resources res= getResources();
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText firstName = (EditText) findViewById(R.id.editTextTextPersonName);
TextView textView = (TextView) findViewById(R.id.textView);
String displayString=res.getString(R.string.hello,firstName.getText().toString());
textView.setText(displayString);
}
});
}

private void initButtonClear() {
Button clear = (Button) findViewById(R.id.button2);
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText firstName = (EditText) findViewById(R.id.editTextTextPersonName);
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Hello World!");
firstName.setText("");
}
});

}
}



Update 9/20/2021:

If you are on the latest version of Android Studio (Android Studio Arctic Fox Version 2020.3.1) and you are on JAVA version 11 or early you may get the following error when executing your (Newly created) Android application:

> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.

SOLUTION:Make sure you load Java11 or later (I have version 15) -

Open the Project get to Files->Settings->Build,Execution,Deployment->Build Tools->Gradle-> Use the drop down for Gradle JDK on that page and select a Java version 11 or later (Which you may have just loaded). I picked JDK 15.

  





Monday, November 16, 2020

Swift: demo

Here is the workaround using repl.it
Circle on Repl.it
This is for use on iOS using XCode


// Declare our new Circle class
class Circle {
    var radius = 0.0
    
    init(radius: Double) { // Constructor
        self.radius = radius
        
    }
    var Area: Double{
        return 3.14*(radius*radius)
    }
    
    func getArea() -> Double {
        return 3.14*(radius*radius)
    }
    
    var Circumference: Double {
        return 2*3.14*radius
    }
    func getCircumference() -> Double{
        return 2*3.14*radius
    }
}


@IBAction func btnCalc(_ sender: UIButton) {
        let rad=Double(tbRad.text!);
        let circ1=Circle(radius:rad!);
        let a=String(format: "%.2f",circ1.getArea());
        let c=circ1.getCircumference();
        lblArea.text="Area: \(a)";
        lblCirc.text="Circumfrence: \(c)";
    }

Monday, October 19, 2020

Xamarin Intro: Hello World

 1) Open MS Visual Studio 2019

2) File-> New Project->C#->Android->Android App (Xamarin) Blank App (
3) Launch the app
You can run the app on your android phone via usb cable
or
Open Android Studio and launch the emulator.
Now you will see that emulator on the Start arrow:
4) Now modify the ui that was created, first stop the app (red square button)
Goto Resources->Layout->Main.axml
- Add a linear (vertical) layout to replay the Relative Layout (see the xml below)
- Add a TextView
- Add a EditView
- Add a button
5) Goto Mainactivity.cs
add code like this after line 17:
            Button button = FindViewById<Button>(Resource.Id.button1);
            TextView tvResult = FindViewById<TextView>(Resource.Id.textView1);
            EditText etName = FindViewById<EditText>(Resource.Id.editText1);
            button.Click += delegate {
                tvResult.Text = "Hello " + etName.Text;
            };
My activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Click Me" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minWidth="25px"
        android:minHeight="25px"
        android:id="@+id/editText1"
        android:hint="Your Name" />
    <TextView
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1" />
</LinearLayout>

MS Visual Studio 2019 Xamarin: How To on Android

Note: The emulator requires that you have an Intel CPU on your workstation.
1) Open MS Visual Studio 2019
2) File-> New Project->C#->Android->Android App (Xamarin) Blank App 
3) In MainActivity.cs
- on line 6 insert
using System;
using Android.Widget; //if not already there
4) Launch the app
You can run the app on your android phone via usb cable
or
Open Android Studio and launch the emulator.
Now you will see that emulator on the Start arrow:
5) Now modify the ui that was created, first stop the app (red square button)
Goto Resources->Layout->Main.axml
- Delete the relative layout.
- Add a linear (vertical) layout (see the xml below)
- Add a TextView
- Add a EditView
- Add a button

  6) Add the Circle class Right Click on the project->New C# Class named Circle.
public class Circle
    {
        private double radius;

        public double Radius
        {
            get
            {
                return radius;
            }
            set
            {
                radius = value;
                if (radius < 0)
                    radius = radius * -1;
            }
        }

        public Circle(double radius)
        {
            this.radius = radius;
        }

        public double getArea()
        {
            return Math.PI * radius * radius;
        }

        public double getCircumference()
        {
            return 2 * Math.PI * radius;
        }
    }
7) Goto Mainactivity.cs
after line 17// SetContentView(Resource.Layout.activity_main);
add code like this: 
Button button = FindViewById<Button>(Resource.Id.button1);
TextView tvResult = FindViewById<TextView>(Resource.Id.textView1);
EditText etRadius = FindViewById<EditText>(Resource.Id.editText1);
button.Click += delegate {
  Circle myCircle = new Circle(Double.Parse(etRadius.Text));
  tvResult.Text = "Area: " + String.Format("{0:0.00}", myCircle.getArea());
  tvResult.Text +="\nCircumference: "+String.Format("{0:0.00}", myCircle.getCircumference());
};

8) You will see this error: The name 'Double' does not exist in the current context
Click on the light bulb and it will add:
using System;

9) If you can not run an emulator and have an android phone:
Get the .apk from here \bin\Debug
Copy it to your phone and install it.

Note see below for a LinearLayout example.
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Calc" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minWidth="25px"
        android:minHeight="25px"
        android:id="@+id/editText1"
        android:hint="Radius" />
    <TextView
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1" />
</LinearLayout>

Week12 Repl.it CircleApp Xamarin workaround using Repl.it

This is a work around if you do not have access to MS Visual Studio 2017 or newer.
CircleApp on Repl.it

Visual Studio 2019 Enterprise Tips

Monday, September 28, 2020

AndroidStudio Projects: Circle how to

package ... //this is the first line in your MainActivity.java 
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initButton();
}
private void initButton()
{
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

EditText rad = (EditText) findViewById(R.id.editTextRadius);
double r = Double.parseDouble(rad.getText().toString());
if (r <= 0)
r = r * -1;

Circle circ= new Circle(r);

TextView textViewA = (TextView) findViewById(R.id.textViewArea);
TextView textViewC = (TextView) findViewById(R.id.textViewCircumference);
textViewA.setText(String.format("Area: %.2f", circ.getArea()));
textViewC.setText(String.format("Circumference: %.2f", circ.getCircumference()));

}
});
}
}
--snip
package ... //this is the first line in your Circle.java file
public class Circle {
    double radius;

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public Circle(double radius){
        this.radius = radius;
    }

    public double getArea(){
        return Math.PI * radius * radius;
    }

    public double getCircumference(){
        return 2 * Math.PI * radius;
    }

}

Wednesday, April 22, 2020

Augusta Technical College Student Services Spring Semester Survey

We have been at our homes for a month; some of you started as online students and some of of you have had the challenge of becoming online students mid-semester. This survey is a check up on how you are doing in your classes and at your home. The end of the survey allows you to share your contact information if you would like some assistance from the College. We want to continue to support you at this time. Please let us know how we can be of assistance. Augusta Technical College Student Services
Spring Semester Survey

Monday, April 20, 2020

Week 16 Platform Revisit

T1 Implement a Triangle Calculator on the platform of your choice.
Calculates the area of a  Equilateral Triangle.
T2 Implement a Triangular Pyramid calculator.
The volume of a  triangular Pyramid
Note: The triangle sides are all the same.
T1 The Area of Equilateral Triangle: K = (1/4) * √3 * len2  
T2 The volume of a triangular Pyramid: 1/3*(√3)/4*(Length*Length)*Height
Square root examples:AppInventor
c: result=sqrt(3);
c#: Math.Sqrt(3);
Java: Math.sqrt(3);
Swift:
let x = 3.0
print(x.squareRoot())



  online Triangular Pyramid Calculator

Equilateral Triangles Calculator

Triangle Calculator

Tuesday, March 24, 2020

Monday, March 16, 2020

Swift using Repl.it


Here is a circle app example using swift on Repl.it.

Ch7 Xamarin Circle class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace Ch7Ex1Circle
{
    public class Circle
    {
        private double radius;

        public double Radius
        {
            get
            {
                return radius;
            }
            set
            {
                radius = value;
                if (radius < 0)
                    radius = radius * -1;
            }
        }

        public Circle(double radius)
        {
            this.Radius = radius;
        }

        public double getArea()
        {
            return Math.PI * radius * radius;
        }

        public double getCircumference()
        {
            return 2 * Math.PI * radius;
        }
    }

}

Monday, October 7, 2019



        let fn=tbFName.text;
        let ln=tbLName.text;
        if(fn == ""  || ln == "")
        {
            lblDisplay.text="Hello World!";
            
        }
        else
        {
            lblDisplay.text = fn!+" "+ln!;
        }